Updated walk() to print out more information on exception#1093
Updated walk() to print out more information on exception#1093nikhilgaba wants to merge 1 commit intopostcss:masterfrom
Conversation
|
@nikhilgaba It is an interesting idea. But we have 5 problems:
If you are ready to pass this way, I will help you on the way :). |
|
How I see a process of adding it to PostCSS:
|
| result = child.walk(callback); | ||
| } | ||
| return result; | ||
| } catch (exception) { |
| // If an error occurs, attempt to print | ||
| // out information that will narrow down | ||
| // where the problem can be found. | ||
| throw new Error( |
There was a problem hiding this comment.
Could this be a new Error Type (Instance) instead please ? So third party implementations can handle it correctly via e.g if (err.name === 'WalkerError') handler... equal to how it works for err.name === 'CssSyntaxError' already
// But not WalkerError please, it's a really bad name :)
class WalkerError extends Error {
constructor (err) {
super()
this.name = 'WalkerError'
this.message = ... // handle/format message (file, message, code frame etc..)
this.stack = ... // handle/format stack trace
Error.captureStackTrace(this, this.constructor)
}
}catch (err) {
throw new WalkerError(err)
}
Forget it. I was wrong in this request (there is no way to detect source node or of |
|
I suggest: } catch (exception) {
if (result.opts.errorSource) {
exception.postcssNode = child
exception.stack = "…"
}
throw exception
} |
|
☝️ How will the thrown postcss(plugins).process(css, options)
.then((result) => result)
.catch((err) => {
// for e.g
err.name === '?'
? new PostCSSError(err) // Syntax Error, Plugin Error, API Error etc...
: new Error(err) // Normal (JS) Error
}) |
|
@nikhilgaba what do you think about my plan? |
|
@ai Plan seems quite sound. I just haven't had a chance to look into the implementation. |
|
Don't worry, I will use power of our Cult of Martians to improve your PR. |
|
I merged and fixed it manually b2530e0 |
|
Released in 7.0 |
This is a modification to the walk() method found for the Container object. The difference from the original is that it now attempts to print out more information to help a developer locate where the problem occurred.