{"action":"opened","issue":{"url":"https://api.github.com/repos/apocas/dockerode/issues/221","repository_url":"https://api.github.com/repos/apocas/dockerode","labels_url":"https://api.github.com/repos/apocas/dockerode/issues/221/labels{/name}","comments_url":"https://api.github.com/repos/apocas/dockerode/issues/221/comments","events_url":"https://api.github.com/repos/apocas/dockerode/issues/221/events","html_url":"https://github.com/apocas/dockerode/issues/221","id":138851266,"number":221,"title":"`docker.buildImage()` handles build errors in a strange way","user":{"login":"jankeromnes","id":599268,"avatar_url":"https://avatars.githubusercontent.com/u/599268?v=3","gravatar_id":"","url":"https://api.github.com/users/jankeromnes","html_url":"https://github.com/jankeromnes","followers_url":"https://api.github.com/users/jankeromnes/followers","following_url":"https://api.github.com/users/jankeromnes/following{/other_user}","gists_url":"https://api.github.com/users/jankeromnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jankeromnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jankeromnes/subscriptions","organizations_url":"https://api.github.com/users/jankeromnes/orgs","repos_url":"https://api.github.com/users/jankeromnes/repos","events_url":"https://api.github.com/users/jankeromnes/events{/privacy}","received_events_url":"https://api.github.com/users/jankeromnes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-06T23:48:16Z","updated_at":"2016-03-06T23:48:16Z","closed_at":null,"body":"When building a Docker image from a Dockerfile, errors can sometimes happen during build (e.g. a compile failure if the Dockerfile tries to compile some project from source). However, `dockerode` seems to handle these in a strange way.\r\n\r\nSay we try to build a Dockerfile with a `RUN cat /thisdoesntexist` instruction:\r\n\r\n    docker.buildImage(tarBuffer, {t: 'mytag'}, function (error, stream) {\r\n      // no `error` yet because the problem happens during build\r\n      // `stream.on('error')` never triggers\r\n      docker.modem.demuxStream(stream, process.stdout, null);\r\n      // stream.on('end') always triggers\r\n    });\r\n\r\nIt seems that the stream doesn't fire any `error` event in case of a build failure. Furthermore, the line with `demuxStream` shows that everything goes to `process.stdout` (trying to write to `null` would crash). Here is what goes to `stdout`:\r\n\r\n    {\"stream\":\"Step 2 : RUN cat /thisdoesntexist\\n\"}\r\n    {\"stream\":\" ---\\u003e Running in 3bfad048a8e2\\n\"}\r\n    {\"stream\":\"\\u001b[91mcat: /thisdoesntexist: No such file or directory\\n\\u001b[0m\"}\r\n    {\"errorDetail\":{\"message\":\"The command [/bin/sh -c cat /thisdoesntexist] returned a non-zero code: 1\"},\"error\":\"The command [/bin/sh -c cat /thisdoesntexist] returned a non-zero code: 1\"}\r\n\r\nI could try to parse `stdout` and watch for objects that have a `errorDetail`, but is this standard behavior? Shouldn't error messages like these go to `stderr` instead?"}}