Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress GaxiosError object dump #827

Closed
Nu11u5 opened this issue Feb 4, 2021 · 4 comments · Fixed by #857
Closed

Suppress GaxiosError object dump #827

Nu11u5 opened this issue Feb 4, 2021 · 4 comments · Fixed by #857

Comments

@Nu11u5
Copy link
Contributor

Nu11u5 commented Feb 4, 2021

Details

When clasp push is run with project files containing invalid syntax, a stack trace is output to stderr. The stack trace contains the full error object including the HTTP request and response objects, headers, authorization tokens, and the appsscript file content itself (which can be quite lengthy). This is extremely verbose, leaks credentials to the terminal, and causes performance issues in some terminals (such as the VSCode terminal).

Proposed Behavior

If clasp receives an error, it only outputs the general error message information. If verbose error information is needed, an additional command parameter could be used to output the stack trace and full error object to stderr.

Specifications

  • Node version: 12.16.3
  • Version: 2.3.0
  • OS: Windows 10 build 18363.1316
@Nu11u5
Copy link
Contributor Author

Nu11u5 commented Feb 4, 2021

As a workaround, stderr can be redirected to null, but this also hides the general error information.

Windows: clasp push 2> nul
Linux: clasp push 2> /dev/null

@Nu11u5
Copy link
Contributor Author

Nu11u5 commented Feb 4, 2021

Example error (anonymized)

Split to allow syntax highlighting

Push failed. Errors:
GaxiosError: Syntax error: SyntaxError: ...
    at Gaxios._request (...\npm\node_modules\@google\clasp\node_modules\gaxios\build\src\gaxios.js:85:23)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async OAuth2Client.requestAsync (...\npm\node_modules\@google\clasp\node_modules\google-auth-library\build\src\auth\oauth2client.js:349:18)
{
  response: {
    config: {
      url: '...',
      method: 'PUT',
      paramsSerializer: [Function],
      data: [Object],
      headers: [Object],
      params: [Object: null prototype] {},
      validateStatus: [Function],
      retry: true,
      body: '{...}',                            //// Multiline text including the appsscript file content, very long ////
      responseType: 'json',
      retryConfig: [Object]
    },
    data: { error: [Object] },
    headers: {
      'alt-svc': '...',
      'cache-control': 'private',
      connection: 'close',
      'content-encoding': 'gzip',
      'content-type': 'application/json; charset=UTF-8',
      date: 'Thu, 04 Feb 2021 21:23:57 GMT',
      server: 'ESF',
      'transfer-encoding': 'chunked',
      vary: 'Origin, X-Origin, Referer',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'SAMEORIGIN',
      'x-xss-protection': '0'
    },
    status: 400,
    statusText: 'Bad Request',
    request: {
      responseURL: 'https://script.googleapis.com/v1/projects/...'
    }
  },
  config: {
    url: 'https://script.googleapis.com/v1/projects/...',
    method: 'PUT',
    paramsSerializer: [Function],
    data: {
      scriptId: '...',
      files: [Array]
    },
    headers: {
      'x-goog-api-client': 'gdcl/3.2.0 gl-node/12.16.3 auth/5.7.0',
      'Accept-Encoding': 'gzip',
      'User-Agent': 'google-api-nodejs-client/3.2.0 (gzip)',
      Authorization: 'Bearer ...',              //// OAuth bearer token is leaked here ////
      'Content-Type': 'application/json',
      Accept: 'application/json'
    },
    params: [Object: null prototype] {},
    validateStatus: [Function],
    retry: true,
    body: '{...}',                              //// Multiline text including the appsscript file content, very long ////
    responseType: 'json',
    retryConfig: {
      currentRetryAttempt: 0,
      retry: 3,
      retryDelay: 100,
      httpMethodsToRetry: [Array],
      noResponseRetries: 2,
      statusCodesToRetry: [Array]
    }
  },
  code: 400,
  errors: [
    {
      message: 'Syntax error: SyntaxError: ...',
      domain: 'global',
      reason: 'badRequest'
    }
  ]
}

@PopGoesTheWza
Copy link
Collaborator

PopGoesTheWza commented Mar 7, 2021

@Nu11u5 can you make a PR for this?

likely around

clasp/src/files.ts

Lines 376 to 378 in ee70a6a

} catch (error) {
console.error(LOG.PUSH_FAILURE);
console.error(error);

Detect if ˋerrorˋ is of the Gaxios persuasion and if it is, process the ˋerror.errorsˋ array?

@PopGoesTheWza
Copy link
Collaborator

@Nu11u5 Just to be sure the issue still exist, can you try replacing @google/clasp 2.3.0 with forked-clasp which is more advanced?

npm uninstall -g @google/clasp
npm install -g forked-clasp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants