Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

couple changes for detecting errors #10

Open
wants to merge 5 commits into from

2 participants

@leafo

There's a few things in here, feel free to cherry pick what you want and throw out the rest.

First, I made sure prefix is created as a directory before building. I had a build script that didn't create it and it was unclear what the error was until I annotated the code.

Second, I save the output from the build command into couch. This is useful if it does build but not correctly. That way you can at least see what happened during the build in the couch web interface or something.

The last three commits capture any exceptions for the make ruby script and save them into couch. Then when you try to get the output via /output/ it checks if there was an error and tells you what it was. Before this patch, the make script would silently fail, and the only error message I would get would be about the missing output attachment.

And a related question. Why is the make script done in ruby? I am kind of new to Heroku so maybe I am missing something but I didn't see a way to capture the output from it. So in my case, things were going wrong but I couldn't tell because the failures were silently ignored.

Thanks for the project.

@ddollar

Sorry I'm getting to this pull request so late. If you're still interested, would you mind rebasing it against master and I'd be happy to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 46 additions and 31 deletions.
  1. +20 −18 server/bin/make
  2. +26 −13 server/web.js
View
38 server/bin/make
@@ -16,30 +16,32 @@ db = CouchRest.database!(ENV["CLOUDANT_URL"] + "/make")
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
doc = db.get(id)
+ begin
+ command = doc["command"]
+ prefix = doc["prefix"]
- command = doc["command"]
- prefix = doc["prefix"]
+ File.open("input.tgz", "wb") do |file|
+ file.print doc.fetch_attachment("input")
+ end
- File.open("input.tgz", "wb") do |file|
- file.print doc.fetch_attachment("input")
- end
+ FileUtils.mkdir_p "input"
+ FileUtils.mkdir_p prefix
- FileUtils.mkdir_p "input"
+ Dir.chdir("input") do
+ %x{ tar xzf ../input.tgz 2>&1 }
+ doc["output"] = `#{command}`
+ db.save_doc(doc)
+ end
- Dir.chdir("input") do
- %x{ tar xzf ../input.tgz 2>&1 }
- system command
- end
+ Dir.chdir(prefix) do
+ %x{ tar czf #{dir}/output.tgz * 2>&1 }
+ end
- Dir.chdir(prefix) do
- %x{ tar czf #{dir}/output.tgz * 2>&1 }
- end
-
- begin
doc.put_attachment("output", File.open("#{dir}/output.tgz"))
- rescue RestClient::Conflict
- # temporarily work around problem with bigcouch
+ rescue => err
+ doc["err"] = err.inspect
+ doc["err_backtrace"] = err.backtrace.join("\n")
+ db.save_doc(doc)
end
-
end
end
View
39 server/web.js
@@ -113,19 +113,32 @@ app.post('/make', function(request, response, next) {
// download build output
app.get('/output/:id', function(request, response, next) {
- // from couchdb
- var stream = db.getAttachment(request.params.id, 'output');
-
- stream.on('error', function(err) {
- console.log('download error: ' + err);
- });
-
- stream.on('data', function(chunk) {
- response.write(chunk, 'binary');
- });
-
- stream.on('end', function(chunk) {
- response.end();
+ db.get(request.params.id, function(err, doc) {
+
+ if (err) { return response.send(err, 404); }
+
+ if (doc.err !== undefined) {
+ response.send({
+ error: "build_failed",
+ msg: doc.err,
+ backtrace: doc.err_backtrace
+ }, 500);
+ } else {
+ // from couchdb
+ var stream = db.getAttachment(request.params.id, 'output');
+
+ stream.on('error', function(err) {
+ console.log('download error: ' + err);
+ });
+
+ stream.on('data', function(chunk) {
+ response.write(chunk, 'binary');
+ });
+
+ stream.on('end', function(chunk) {
+ response.end();
+ });
+ }
});
});
Something went wrong with that request. Please try again.