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

Graceful lumo exit on compiler failure. Support lumo >= 1.8.0. #22

Closed
wants to merge 1 commit into from

Conversation

arichiardi
Copy link
Contributor

@arichiardi arichiardi commented Sep 12, 2017

This patch fixes the fact that serverless could not display compilation ailures because lumo was not returning anything. Now lumo.build.api accepts a callback that returns the error.
This feature is only available in the latest lumo (>= 1.8.0) so the README now makes clear that other versions won't be supported.

compiler-opts
nil
#(let [promise-fn (if (:error %) reject resolve)]
(promise-fn %))))))
Copy link
Member

Choose a reason for hiding this comment

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

This would be clearer if the only statement inside the promise was:

(js/Promise.
  (fn [resolve reject]
    (lumo.build.api/build
       ...
       (fn [result]
         (if (:error result)
           (reject result)
           (resolve result))))

What happens if the user doesn't have the latest lumo?

@arichiardi
Copy link
Contributor Author

arichiardi commented Sep 13, 2017 via email

@arichiardi
Copy link
Contributor Author

My PR is not in lumo yet and I am waiting for feedback from Antonio. I fixed this, but we'd better wait. In the meantime, I fixed another problem in another PR.

@arichiardi arichiardi force-pushed the lumo-exit branch 3 times, most recently from ec18af7 to f29937a Compare September 16, 2017 00:36
@arichiardi
Copy link
Contributor Author

So this is now in lumo 1.8.0-beta and I don't think it is a feature that can be retrofitted: before the lumo.build.api call was only able to return the compilation result synchronously. This means that we versions older than this new one, if compilation fails things gets weird.

@arichiardi
Copy link
Contributor Author

arichiardi commented Sep 19, 2017

On second thought, this one now should work for older lumos as well because the compiler function probably throws on errors, making the promise reject anyways.

@moea
Copy link
Member

moea commented Sep 19, 2017

Yeah, but if the signature doesn't include a callback argument, presumably it'll be a problem?

@arichiardi
Copy link
Contributor Author

Oh right, well what do you think is the best approach? I think lumo compilation before this version is not worth keeping compatibility with, as you have probably guess it was very experimental.

@moea
Copy link
Member

moea commented Sep 19, 2017

If we clearly document the status of the lumo dependency in the README (either a commit hash or version #, whatever's applicable), then I'm fine with the change.

@arichiardi
Copy link
Contributor Author

Ok I will add that, there is an actual version published on npm, 1.8.0-beta1 .

@moea
Copy link
Member

moea commented Sep 19, 2017

If you get a moment, can you address the previous review comment which suggested removing everything from the Promise monad except for the final build call?

@arichiardi
Copy link
Contributor Author

Sure, do you mean the console.log? The add-classpath is better inside in case it throws

@moea
Copy link
Member

moea commented Sep 19, 2017

If it throws outside the promise, the process will exit irregularly in any case.

@arichiardi arichiardi force-pushed the lumo-exit branch 3 times, most recently from 09cdeb3 to 68e601e Compare September 19, 2017 18:36
README.md Outdated
[compiler](https://anmonteiro.com/2017/02/compiling-clojurescript-projects-without-the-jvm/).

Note that `serverless-cljs-plugin` needs _Lumo >= 1.8.0_.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, let me know if you would like me to change the style of this.

@@ -69,7 +77,6 @@
{:source-paths ["src"]
:compiler {:output-to (.format path #js {:dir "out" :base "lambda.js"})
:output-dir "out"
:source-map false ;; lumo bug
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed anymore given that it has been solved in Lumo 1.8.0-beta1

(build! opts (merge-maps default-config (read-conf!)))))
(.then (build! opts (merge-maps default-config (read-conf!)))
lumo/exit
#(lumo/exit 2))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put 2 in order to differentiate it from the normal exit code for throws, which is 1.

@arichiardi arichiardi changed the title Handle exit by promisifying lumo compilation Graceful lumo exit on compiler failure. Support lumo >= 1.8.0. Sep 19, 2017
This patch fixes the fact that `serverless` could not display compilation
ailures because `lumo` was not returning anything. Now `lumo.build.api` accepts
a callback that returns the error.
This feature is only available in the latest lumo (>= 1.8.0) so the
README now makes clear that other versions won't be supported.
@arichiardi
Copy link
Contributor Author

So I think that thanks to anmonteiro/lumo@80192d1 this patch can be entirely dropped. The build api is sync now.

@arichiardi arichiardi closed this Sep 25, 2017
@arichiardi arichiardi deleted the lumo-exit branch September 25, 2017 21:52
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.

None yet

2 participants