#Non-Empty String Error Doesn't Make Sense

27 messages · Page 1 of 1 (latest)

long blaze
#

Our Postman API call worked, but still returned this error. A second attempt to use the API call does result in an ECONNREFUSED error. The same error happens when using the dev front-end app. The first call kicks of a redirect (which is part of the success pipeline), but the second call errors out immediately.

Error:

/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/@phc/format/index.js:143
    throw new TypeError('pchstr must be a non-empty string');
          ^
TypeError: pchstr must be a non-empty string
minor token
#

Where do you use this @pch/format library? What's the context of what's happening?

long blaze
#

This web app was working a month ago. Haven't touched it until yesterday. All of a sudden, we've got errors that we didn't have before.

minor token
#

Workout a stack trace I've got no clue

long blaze
#

Axios Error part 1:

AxiosError@http://localhost:3000/static/js/bundle.js:91322:18
handleError@http://localhost:3000/static/js/bundle.js:90717:14
EventHandlerNonNull*dispatchXhrRequest@http://localhost:3000/static/js/bundle.js:90714:5
./node_modules/axios/lib/adapters/xhr.js/__WEBPACK_DEFAULT_EXPORT__<@http://localhost:3000/static/js/bundle.js:90623:10
  dispatchRequest@http://localhost:3000/static/js/bundle.js:91789:10
  request@http://localhost:3000/static/js/bundle.js:91239:77
  wrap@http://localhost:3000/static/js/bundle.js:92378:15
  userLogin@http://localhost:3000/main.aa9529d7c6c85947e89b.hot-update.js:39:72
  submitLogin@http://localhost:3000/main.aa9529d7c6c85947e89b.hot-update.js:61:23
  onClick@http://localhost:3000/main.aa9529d7c6c85947e89b.hot-update.js:95:18
  callCallback@http://localhost:3000/static/js/bundle.js:56241:18
  invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:56285:20
  invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:56342:35
  invokeGuardedCallbackAndCatchFirstError@http://localhost:3000/static/js/bundle.js:56356:29
  executeDispatch@http://localhost:3000/static/js/bundle.js:60500:46
  processDispatchQueueItemsInOrder@http://localhost:3000/static/js/bundle.js:60526:26
  processDispatchQueue@http://localhost:3000/static/js/bundle.js:60537:41
  dispatchEventsForPlugins@http://localhost:3000/static/js/bundle.js:60546:27
  ./node_modules/react-dom/cjs/react-dom.development.js/dispatchEventForPluginEventSystem/<@http://localhost:3000/static/js/bundle.js:60706:16
  batchedUpdates$1@http://localhost:3000/static/js/bundle.js:75098:16
  batchedUpdates@http://localhost:3000/static/js/bundle.js:56089:16
  dispatchEventForPluginEventSystem@http://localhost:3000/static/js/bundle.js:60705:21
#

Axios Error part 2:

dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay@http://localhost:3000/static/js/bundle.js:58211:42
  dispatchEvent@http://localhost:3000/static/js/bundle.js:58205:88
  dispatchDiscreteEvent@http://localhost:3000/static/js/bundle.js:58182:22
  EventListener.handleEvent*addEventBubbleListener@http://localhost:3000/static/js/bundle.js:58404:14
  addTrappedEventListener@http://localhost:3000/static/js/bundle.js:60628:33
  listenToNativeEvent@http://localhost:3000/static/js/bundle.js:60572:30
  ./node_modules/react-dom/cjs/react-dom.development.js/listenToAllSupportedEvents/<@http://localhost:3000/static/js/bundle.js:60583:34
  listenToAllSupportedEvents@http://localhost:3000/static/js/bundle.js:60578:25
  createRoot@http://localhost:3000/static/js/bundle.js:77861:33
  createRoot$1@http://localhost:3000/static/js/bundle.js:78207:14
  ./node_modules/react-dom/client.js/exports.createRoot@http://localhost:3000/static/js/bundle.js:78283:16
  ./src/index.tsx@http://localhost:3000/static/js/bundle.js:2093:60
  options.factory@http://localhost:3000/static/js/bundle.js:95725:31
  __webpack_require__@http://localhost:3000/static/js/bundle.js:95171:33
  @http://localhost:3000/static/js/bundle.js:96307:56
  @http://localhost:3000/static/js/bundle.js:96309:12
#

Axios Error Part 3 (after stack trace):

{
  "message": "Network Error",
  "name": "AxiosError",
  "code": "ERR_NETWORK",
  "config": {
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    },
    "adapter": [
      "xhr",
      "http"
    ],
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 0,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "env": {},
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json"
    },
    "method": "post",
    "url": "http://localhost:8000/v1/account/login/",
    "data": "{\"email\":\"[email protected]\",\"password\":\"test1234\"}",
    "withCredentials": true
  },
  "request": {}
}
#

The Axios stuff above is from the client-side attempt. The stuff below is the full error in the terminal. This is the error for both Postman and the React app.

/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/@phc/format/index.js:143
    throw new TypeError('pchstr must be a non-empty string');
          ^
TypeError: pchstr must be a non-empty string
    at deserialize (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/@phc/format/index.js:143:11)
    at Object.verify (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/argon2/argon2.js:79:15)
    at AccountService.login (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/src/account/account.service.ts:160:47)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
minor token
#

Looks like an error inside of argon2 in your account service's login method

long blaze
#

I see what you're saying. 3rd line in the terminal stack trace. BUT...that doesn't make sense.

minor token
#

Does it not? Without knowing your code I can't say

long blaze
#

Here is that code:

const passwordValidateSuccess = argon.verify(
  user.password,
  data.password
);
minor token
#

So one of those values is '' or undefined or similar

long blaze
#

If I restart my Nest.js backend API in the terminal, and run Postman again. I get a success output.

{
    "data": {
        "status": "success",
        "access_token": "token-here"
    }
}
#

My terminal also throws the same error as before:

[Nest] 5603  - 03/12/2023, 5:18:34 PM     LOG [NestApplication] Nest application successfully started +3ms
Before...

/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/@phc/format/index.js:143
    throw new TypeError('pchstr must be a non-empty string');
          ^
TypeError: pchstr must be a non-empty string
    at deserialize (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/@phc/format/index.js:143:11)
    at Object.verify (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/argon2/argon2.js:79:15)
    at AccountService.login (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/src/account/account.service.ts:160:47)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
#

How can I get a "success" and a conflicting error that should've prevented the success?

minor token
#

Argon verify is an async function, right? It should be awaited

long blaze
#

After adding an await, the error hits hard. Guessing it was a warning before?

[Nest] 5656  - 03/12/2023, 5:21:12 PM     LOG [NestApplication] Nest application successfully started +3ms
Before...
[Nest] 5656  - 03/12/2023, 5:21:16 PM   ERROR [ExceptionsHandler] pchstr must be a non-empty string
TypeError: pchstr must be a non-empty string
    at deserialize (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/@phc/format/index.js:143:11)
    at Object.verify (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/node_modules/argon2/argon2.js:79:15)
    at AccountService.login (/Applications/MAMP/htdocs/_Websites/veterandb.com/backend/src/account/account.service.ts:160:53)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

minor token
#

The error is now being properly reported inside the request lifecycle

#

Have you verified the values you are passing are indeed defined and not empty strings?

long blaze
#

Yes. It's defined. The screenshot is from the web app. You can see that "config.data" is sending the same data.

POSTMAN VALUES

{
  "email": "[email protected]",
  "password": "{{password}}"
}
minor token
#

But in the service, are they defined there?

#

Start from where the error is and work your way out to find the undefined value, right?

long blaze
#

I'll need some time to setup a smattering of console.logs to figure it out. I can say for certain that it should work, as I've used this endpoint in Postman and the web app hundreds of times, and nothing has changed on the logic for this.

long blaze
#

Found the problem.

#

The logic wasn't changed, but we did hide the password from the entity results awhile back.

// ENTITY
@Column({ select: false })

// update needed to include select for the password
const user = await this.accountRepository.findOne({
  where: {
    email: data.email
  },
  select: {
    password: true
  }
});