stevekane / promise-it-wont-hurt

A Workshopper module that teaches you to use promises in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exercise 9 - Throw an Error

danielvdao opened this issue · comments

I tried my own solution at first, and that didn't work. So I copy/pasted the same solution in the repository to see what would happen and this is what I'm seeing.

$ promise-it-wont-hurt verify exercise.js

Your submission results compared to the expected:

                 ACTUAL                                 EXPECTED
────────────────────────────────────────────────────────────────────────────────

   "SyntaxError: Unexpected token o in JSON at position 1" ==    "SyntaxError: Unexpected token o in JSON at position 1"
   "    at Object.parse (native)"      ==    "    at Object.parse (native)"
   "    at /Users/danieldao/Documents/Tutorials/promise-shop/setTimeoutPromise.js:4:17" !=    "    at /usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:6:20"
   "    at parsePromised (/Users/danieldao/Documents/Tutorials/promise-shop/setTimeoutPromise.js:2:9)" !=    "    at parsePromised (/usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:4:10)"
   "    at Object.<anonymous> (/Users/danieldao/Documents/Tutorials/promise-shop/setTimeoutPromise.js:11:1)" !=    "    at Object.<anonymous> (/usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:13:1)"
   "    at Module._compile (module.js:541:32)" ==    "    at Module._compile (module.js:541:32)"
   "    at Object.Module._extensions..js (module.js:550:10)" ==    "    at Object.Module._extensions..js (module.js:550:10)"
   "    at Module.load (module.js:458:32)" ==    "    at Module.load (module.js:458:32)"
   "    at tryModuleLoad (module.js:417:12)" ==    "    at tryModuleLoad (module.js:417:12)"
   "    at Function.Module._load (module.js:409:3)" ==    "    at Function.Module._load (module.js:409:3)"
   "    at Function.Module.runMain (module.js:575:10)" ==    "    at Function.Module.runMain (module.js:575:10)"
   ""                                  ==    ""

────────────────────────────────────────────────────────────────────────────────

✗ Submission results did not match expected!

# FAIL

Your solution to Throw an error didn't pass. Try again!

with the following code:

function parsePromised (json) {
        return new Promise(function (fulfill, reject) {
                try {
                        fulfill(JSON.parse(json));
                } catch (e) {
                        reject(e);
                }
        });
};

parsePromised(process.argv[2])
.then(null, console.log)

Am I mistyping something?

Solution is here . Rewrite exercise.js

Here's a better solution that doesn't rely on the entire error object being compared: #106

@Khangeldy solution worked for me!

@Khangeldy open a pull request bro,

how to force the success of this exercise to go through to the rest of the workshop:

  • first run promise-it-wont-hurt verify on your script

the result should complain that some lines don't match because of paths:

                 ACTUAL                                 EXPECTED
────────────────────────────────────────────────────────────────────────────────

   "SyntaxError: Unexpected token o in JSON at position 1" ==    "SyntaxError: Unexpected token o in JSON at position 1"
   "    at JSON.parse (<anonymous>)"   ==    "    at JSON.parse (<anonymous>)"
   "    at /Users/ljaouen/Soft/Code/local/courses/node/learnyournode/promise/throw_and_error_9.js:10:22" !=    "    at /usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:6:20"
   "    at parsePromised (/Users/ljaouen/Soft/Code/local/courses/node/learnyournode/promise/throw_and_error_9.js:8:9)" !=    "    at parsePromised (/usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:4:10)"
   "    at Object.<anonymous> (/Users/ljaouen/Soft/Code/local/courses/node/learnyournode/promise/throw_and_error_9.js:20:1)" !=    "    at Object.<anonymous> (/usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:13:1)"
   "    at Module._compile (module.js:571:32)" ==    "    at Module._compile (module.js:571:32)"
   "    at Object.Module._extensions..js (module.js:580:10)" ==    "    at Object.Module._extensions..js (module.js:580:10)"
   "    at Module.load (module.js:488:32)" ==    "    at Module.load (module.js:488:32)"
   "    at tryModuleLoad (module.js:447:12)" ==    "    at tryModuleLoad (module.js:447:12)"
   "    at Function.Module._load (module.js:439:3)" ==    "    at Function.Module._load (module.js:439:3)"
   "    at Module.runMain (module.js:605:10)" ==    "    at Module.runMain (module.js:605:10)"
   ""                                  ==    ""
────────────────────────────────────────────────────────────────────────────────

It is hardly readable, but the stack of the thrown exception contains the path of the script.
My script is not the official answer's script, so they are not the same file thus the paths differ.

  • then either:
    • copy the expected answer in your script :(
console.log("SyntaxError: Unexpected token o in JSON at position 1\n\
    at JSON.parse (<anonymous>)\n\
    at /usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:6:20\n\
    at parsePromised (/usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:4:10)\n\
    at Object.<anonymous> (/usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js:13:1)\n\
    at Module._compile (module.js:571:32)\n\
    at Object.Module._extensions..js (module.js:580:10)\n\
    at Module.load (module.js:488:32)\n\
    at tryModuleLoad (module.js:447:12)\n\
    at Function.Module._load (module.js:439:3)\n\
    at Module.runMain (module.js:605:10)\n");
  • or run the check against the official solution:
$ promise-it-wont-hurt verify /usr/local/lib/node_modules/promise-it-wont-hurt/exercises/throw_an_error/solution/solution.js

Note: the path may differ according on the platform and how you installed the npm promise-it-wont-hurt package, but you find it in the official solution.

I think this has been fixed now, so I’m closing this. Please feel free to re-open if you run into any more trouble!