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

11ty's error messages for failed plugins are not helpful #646

Closed
surma opened this issue Aug 7, 2019 · 4 comments
Closed

11ty's error messages for failed plugins are not helpful #646

surma opened this issue Aug 7, 2019 · 4 comments

Comments

@surma
Copy link

surma commented Aug 7, 2019

Describe the bug
If a plugin throws (or returns a rejected promise), the error message contains no information about which plugin is throwing and where the throw happened.

To Reproduce
Create a new 11ty project with just a README and put this in your .eleventy.js:

// .eleventy.js
module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin({
    configFunction(eleventyConfig) {
      eleventyConfig.addTransform("test", async function(
        rawContent,
        outputPath
      ) {
        throw Error("Oh no my plugin failed");
      });
    }
  });
};

Running eleventy yields:

Error writing templates: (more in DEBUG output)
> Having trouble writing template: _site/README/index.html (TemplateWriterWriteError)
> Oh no my plugin failed (Error):
    Error: Oh no my plugin failed
        at Template.<anonymous> (/Users/surma/src/scratch/eleventy-error/.eleventy.js:8:15)
        at Template.runTransforms (/Users/surma/.nvm/versions/node/v12.4.0/lib/node_modules/@11ty/eleventy/src/Template.js:384:29)
        at Template.renderPageEntry (/Users/surma/.nvm/versions/node/v12.4.0/lib/node_modules/@11ty/eleventy/src/Template.js:537:28)
        at async Template.writeMapEntry (/Users/surma/.nvm/versions/node/v12.4.0/lib/node_modules/@11ty/eleventy/src/Template.js:545:21)
Processed 0 files in 0.07 seconds

Running DEBUG=1 eleventy yields less useful information, imo:

0.8.3

Start time: (2019-08-07 14:33:14 UTC) [treshold=1%]

module time %

1 fs-extra (../....lib/index.js) 17ms ▇▇ 5%
2 ./TemplatePath...platePath.js) 22ms ▇▇ 6%
3 to-regex (../....gex/index.js) 8ms ▇ 2%
4 ./utils (../.....lib/utils.js) 6ms ▇ 2%
5 ./lib/compiler...compilers.js) 7ms ▇ 2%
6 snapdragon-nod...ode/index.js) 4ms ▇ 1%
7 ./lib/parsers...b/parsers.js) 4ms ▇ 1%
8 cache-base (.....ase/index.js) 9ms ▇ 2%
9 class-utils (....ils/index.js) 5ms ▇ 1%
10 base (../../.....ase/index.js) 21ms ▇▇ 6%
11 source-map (.....ource-map.js) 4ms ▇ 1%
12 ./utils (../.....lib/utils.js) 6ms ▇ 2%
13 ./lib/compiler.../compiler.js) 9ms ▇ 2%
14 snapdragon (.....gon/index.js) 32ms ▇▇▇ 8%
15 ./lib/braces (...ib/braces.js) 32ms ▇▇▇ 8%
16 braces (../../...ces/index.js) 52ms ▇▇▇▇▇ 14%
17 expand-bracket...ets/index.js) 4ms ▇ 1%
18 ./lib/compiler...compilers.js) 4ms ▇ 1%
19 extglob (../.....lob/index.js) 8ms ▇ 2%
20 ./lib/compiler...compilers.js) 12ms ▇ 3%
21 micromatch (.....tch/index.js) 66ms ▇▇▇▇▇▇ 18%
22 ../utils/patte...s/pattern.js) 69ms ▇▇▇▇▇▇ 18%
23 ./managers/tas...ers/tasks.js) 69ms ▇▇▇▇▇▇ 18%
24 ./providers/re...der-async.js) 8ms ▇ 2%
25 ./out/index (....out/index.js) 80ms ▇▇▇▇▇▇▇ 21%
26 fast-glob (../...lob/index.js) 80ms ▇▇▇▇▇▇▇ 21%
27 ./_baseIsNativ...eIsNative.js) 4ms ▇ 1%
28 ./_getNative (...getNative.js) 4ms ▇ 1%
29 ./_definePrope...eProperty.js) 4ms ▇ 1%
30 ./_baseAssignV...signValue.js) 4ms ▇ 1%
31 ./_assignValue...signValue.js) 5ms ▇ 1%
32 ./_MapCache (...._MapCache.js) 4ms ▇ 1%
33 ./memoize (../...h/memoize.js) 4ms ▇ 1%
34 ./_memoizeCapp...izeCapped.js) 4ms ▇ 1%
35 ./_stringToPat...ingToPath.js) 4ms ▇ 1%
36 ./_castPath (...._castPath.js) 5ms ▇ 1%
37 ./_baseSet (...../_baseSet.js) 12ms ▇ 3%
38 lodash/set (.....odash/set.js) 12ms ▇ 3%
39 ./_baseMergeDe...MergeDeep.js) 5ms ▇ 1%
40 ./_baseMerge (...baseMerge.js) 7ms ▇ 2%
41 lodash/merge (...ash/merge.js) 9ms ▇ 2%
42 @babel/parser...lib/index.js) 6ms ▇ 2%
43 node-source-wa...alk/index.js) 7ms ▇ 2%
44 module-definit...ion/index.js) 7ms ▇ 2%
45 escodegen (../...escodegen.js) 5ms ▇ 1%
46 detective-amd...amd/index.js) 5ms ▇ 1%
47 gonzales-pe (..../gonzales.js) 11ms ▇ 3%
48 detective-less...ess/index.js) 12ms ▇ 3%
49 ./previous-map...vious-map.js) 4ms ▇ 1%
50 ./input (../.....lib/input.js) 4ms ▇ 1%
51 ./terminal-hig...highlight.js) 5ms ▇ 1%
52 ./css-syntax-e...tax-error.js) 6ms ▇ 2%
53 ./node (../../.../lib/node.js) 7ms ▇ 2%
54 ./declaration...claration.js) 8ms ▇ 2%
55 ./lazy-result...zy-result.js) 4ms ▇ 1%
56 ./processor (....processor.js) 6ms ▇ 2%
57 postcss (../.....b/postcss.js) 14ms ▇▇ 4%
58 ./parser (../....ib/parser.js) 6ms ▇ 2%
59 postcss-values...lib/index.js) 6ms ▇ 2%
60 detective-post...ist/index.js) 21ms ▇▇ 6%
61 typescript (.....ypescript.js) 110ms ▇▇▇▇▇▇▇▇▇ 29%
62 typescript-esl...er/parser.js) 117ms ▇▇▇▇▇▇▇▇▇▇ 31%
63 detective-type...ipt/index.js) 117ms ▇▇▇▇▇▇▇▇▇▇ 31%
64 precinct (../....nct/index.js) 165ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 44%
65 dependency-tre...ree/index.js) 169ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 45%
66 ./UserConfig (...serConfig.js) 6ms ▇ 2%
67 ./EleventyConf...ntyConfig.js) 6ms ▇ 2%
68 ./TemplateConf...ateConfig.js) 184ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 49%
69 ../config.js (...ty/config.js) 4ms ▇ 1%
70 ./Config (../....rc/Config.js) 192ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 51%
71 ../EleventyExt...ensionMap.js) 192ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 51%
72 ./Engines/Temp...ateEngine.js) 192ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 51%
73 ./TemplateRend...ateRender.js) 193ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 51%
74 ./TemplateData...plateData.js) 288ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 76%
75 ./schema/defau...ault_safe.js) 7ms ▇ 2%
76 esprima (../.....t/esprima.js) 6ms ▇ 2%
77 ../type/js/fun.../function.js) 6ms ▇ 2%
78 ./schema/defau...ault_full.js) 7ms ▇ 2%
79 ./js-yaml/load...ml/loader.js) 15ms ▇▇ 4%
80 ./lib/js-yaml....b/js-yaml.js) 16ms ▇▇ 4%
81 js-yaml (../.....aml/index.js) 17ms ▇▇ 5%
82 ./engines (../...b/engines.js) 17ms ▇▇ 5%
83 ./lib/defaults.../defaults.js) 18ms ▇▇ 5%
84 gray-matter (....ter/index.js) 20ms ▇▇ 5%
85 ./TemplateCont...teContent.js) 22ms ▇▇ 6%
86 ./Template (...../Template.js) 25ms ▇▇ 7%
87 ./TemplateColl...ollection.js) 4ms ▇ 1%
88 ./TemplateMap...mplateMap.js) 5ms ▇ 1%
89 glob (../../.....glob/glob.js) 4ms ▇ 1%
90 globby (../../...bby/index.js) 5ms ▇ 1%
91 del (../../../...del/index.js) 8ms ▇ 2%
92 ./lib/copy (...../lib/copy.js) 12ms ▇ 3%
93 recursive-copy...opy/index.js) 12ms ▇ 3%
94 ./TemplatePass...ssthrough.js) 13ms ▇▇ 3%
95 ./TemplatePass...ghManager.js) 13ms ▇▇ 3%
96 ./EleventyFile...entyFiles.js) 13ms ▇▇ 3%
97 ./TemplateWrit...ateWriter.js) 44ms ▇▇▇▇ 12%
98 ./src/Eleventy.../Eleventy.js) 355ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 94%
Total require(): 1296
Total time: 377ms

Expected behavior
A clear and concise description of what you expected to happen which plugin failed and where it threw.

Environment:

  • OS and Version: Mac
  • Eleventy Version 0.8.3

Additional context
On my personal blog I have a more complex plugin that is located in its own file. For some reason, the output becomes even more cryptic:

Error writing templates: (more in DEBUG output)
> Class constructor TemplateWriterWriteError cannot be invoked without 'new'

TypeError was thrown:
TypeError: Class constructor TemplateWriterWriteError cannot be invoked without 'new'
at /Users/surma/src/github.com/surma/surma.github.io/node_modules/@11ty/eleventy/src/TemplateWriter.js:169:13
at async Promise.all (index 1)
at async Eleventy.write (/Users/surma/src/github.com/surma/surma.github.io/node_modules/@11ty/eleventy/src/Eleventy.js:423:13)
Problem writing Eleventy templates: (more in DEBUG output)

Class constructor TemplateWriterWriteError cannot be invoked without 'new'

TypeError was thrown:
TypeError: Class constructor TemplateWriterWriteError cannot be invoked without 'new'
at /Users/surma/src/github.com/surma/surma.github.io/node_modules/@11ty/eleventy/src/TemplateWriter.js:169:13
at async Promise.all (index 1)
at async Eleventy.write (/Users/surma/src/github.com/surma/surma.github.io/node_modules/@11ty/eleventy/src/Eleventy.js:423:13)
Processed 0 files in 0.64 seconds

@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Aug 7, 2019

Related to #547?

@zachleat
Copy link
Member

Just as a quick note, I believe Class constructor TemplateWriterWriteError cannot be invoked without 'new' was a regression in the latest 0.9.0 beta. It was fixed in #650.

@zachleat
Copy link
Member

Finally getting back to this. Errors triggering from transforms will now look like this starting in 1.0.1. If you’d like me to provide better error messaging around other features, please let me know!

~/Temp/eleventy-issue-646 ᐅ npx @11ty/eleventy
Problem writing Eleventy templates: (more in DEBUG output)
1. Having trouble writing template: "_site/test/index.html" (via EleventyTemplateError)
2. Transform `test` encountered an error when transforming ./test.md. (via EleventyTransformError)
3. Oh no my plugin failed (via Error)

Original error stack trace: Error: Oh no my plugin failed
    at Object.<anonymous> (/Users/zachleat/Temp/eleventy-issue-646/.eleventy.js:9:15)
    at Template.runTransforms (/Users/zachleat/Code/eleventy/src/Template.js:557:30)
    at Template.renderPageEntry (/Users/zachleat/Code/eleventy/src/Template.js:855:26)
    at async /Users/zachleat/Code/eleventy/src/Template.js:879:21
    at async Promise.all (index 0)
Wrote 0 files in 0.03 seconds (v1.0.1-canary.2)

@zachleat zachleat self-assigned this Feb 16, 2022
@zachleat
Copy link
Member

Also pushing another improvement here for plugin execution specifically (the original error was a transform error but it sounds like @surma wanted better messaging around plugins too)

Specifically:

// .eleventy.js
module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin({
    configFunction: function myPluginName(eleventyConfig) {
      throw Error("Oh no my plugin failed");
    }
  });
};

will now throw an error like this:

Eleventy CLI Fatal Error: (more in DEBUG output)
1. Error processing the myPluginName plugin (via EleventyPluginError)
2. Oh no my plugin failed (via Error)

Original error stack trace: Error: Oh no my plugin failed
    at Object.myPluginName [as configFunction] (/Users/zachleat/Temp/eleventy-issue-646/.eleventy.js:12:13)
    at UserConfig._executePlugin (/Users/zachleat/Code/eleventy/src/UserConfig.js:370:14)
    at TemplateConfig.processPlugins (/Users/zachleat/Code/eleventy/src/TemplateConfig.js:192:25)
    at TemplateConfig.mergeConfig (/Users/zachleat/Code/eleventy/src/TemplateConfig.js:272:10)
    at TemplateConfig.getConfig (/Users/zachleat/Code/eleventy/src/TemplateConfig.js:122:26)
    at new Eleventy (/Users/zachleat/Code/eleventy/src/Eleventy.js:73:39)
    at Object.<anonymous> (/Users/zachleat/Code/eleventy/cmd.js:65:14)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

Note that we’ll use Function.name in the error message to give a little bit more info (if it’s available) since plugins don’t have a top-level name property by default.

zachleat added a commit that referenced this issue Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants