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

fix(gatsby-plugin-sharp): avoid joi validation error when using reporter.panic #28291

Merged
merged 1 commit into from
Nov 27, 2020

Conversation

rburgst
Copy link
Contributor

@rburgst rburgst commented Nov 25, 2020

Description

fix joi error when image conversion fails

previously just passing the error object would produce the following joi error

Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/myproject/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/myproject/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/myproject/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /myproject/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,

Related Issues

  • N/A

- previously just passing the error object would produce a joi
  error

```
Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/myproject/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/myproject/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/myproject/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /myproject/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,
```
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 25, 2020
@rburgst rburgst changed the title fix: avoid joi validation error when using reporter.panic fix(gatsby-plugin-sharp): avoid joi validation error when using reporter.panic Nov 26, 2020
@LekoArts LekoArts added topic: sharp and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Nov 26, 2020
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

It seems something is throwing an object with unexpected name field here, right? In any case - this is ok to get in as-is

When I tried artificially cause this:

I got

Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/Users/misiek/dev/gatsby-starter-blog/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/Users/misiek/dev/gatsby-starter-blog/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/Users/misiek/dev/gatsby-starter-blog/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/Users/misiek/dev/gatsby-starter-blog/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/Users/misiek/dev/gatsby-starter-blog/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/Users/misiek/dev/gatsby-starter-blog/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/Users/misiek/dev/gatsby-starter-blog/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /Users/misiek/dev/gatsby-starter-blog/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,
  details: [
    {
      message: '"name" is not allowed',
      path: [Array],
      type: 'object.allowUnknown',
      context: [Object]
    }
  ],
  _object: {
    context: {},
    name: 'WorkerError',
    pluginName: 'gatsby-transformer-sharp',
    text: 'There was an error',
    level: 'ERROR',
    stack: [],
    docsUrl: 'https://gatsby.dev/issue-how-to'
  },
  annotate: [Function]
}

and with your change I got:


 ERROR 

[object Object] {"name":true}



  WorkerError: {"name":true}
  
  - jobs-manager.ts:318 enqueueJob
    [gatsby-starter-blog]/[gatsby]/src/utils/jobs-manager.ts:318:21
  

Which is still not great, but at least the thrown thing is not hidden

Thanks again!

@pieh pieh merged commit 231cf9f into gatsbyjs:master Nov 27, 2020
pieh pushed a commit that referenced this pull request Nov 27, 2020
- previously just passing the error object would produce a joi
  error

```
Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/myproject/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/myproject/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/myproject/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /myproject/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,
```

(cherry picked from commit 231cf9f)
pieh pushed a commit that referenced this pull request Nov 27, 2020
- previously just passing the error object would produce a joi
  error

```
Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/myproject/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/myproject/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/myproject/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /myproject/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,
```

(cherry picked from commit 231cf9f)
pieh added a commit that referenced this pull request Nov 27, 2020
…28321)

- previously just passing the error object would produce a joi
  error

```
Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/myproject/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/myproject/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/myproject/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /myproject/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,
```

(cherry picked from commit 231cf9f)

Co-authored-by: rburgst <rburgst@gmail.com>
@pieh
Copy link
Contributor

pieh commented Nov 27, 2020

I just published gatsby-plugin-sharp@2.9.1 to npm with this change.

It might take some time to propagate (npm info gatsby-plugin-sharp already shows it, but https://www.npmjs.com/package/gatsby-plugin-sharp doesn't yet) - this is just info in case someone has trouble installing it right now

gatsbybot pushed a commit that referenced this pull request Nov 27, 2020
…28322)

- previously just passing the error object would produce a joi
  error

```
Failed to validate error Error [ValidationError]: "name" is not allowed
    at Object.exports.process (/myproject/node_modules/@hapi/joi/lib/errors.js:202:19)
    at internals.Object._validateWithOptions (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:763:31)
    at internals.Object.validate (/myproject/node_modules/@hapi/joi/lib/types/any/index.js:797:21)
    at constructError (/myproject/node_modules/gatsby-cli/lib/structured-errors/construct-error.js:52:32)
    at Reporter.error (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:135:59)
    at Reporter.panic (/myproject/node_modules/gatsby-cli/lib/reporter/reporter.js:75:34)
    at Object.panic (/myproject/node_modules/gatsby/src/utils/api-runner-node.js:201:16)
    at /myproject/node_modules/gatsby-plugin-sharp/index.js:162:14 {
  isJoi: true,
```

(cherry picked from commit 231cf9f)

Co-authored-by: rburgst <rburgst@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants