diff --git a/src/common.cc b/src/common.cc index 1ba6fe8d3..4e04f786d 100644 --- a/src/common.cc +++ b/src/common.cc @@ -226,6 +226,13 @@ namespace sharp { return EndsWith(str, ".v") || EndsWith(str, ".V") || EndsWith(str, ".vips") || EndsWith(str, ".VIPS"); } + /* + Trim space from end of string. + */ + std::string TrimEnd(std::string const &str) { + return str.substr(0, str.find_last_not_of(" \n\r\f") + 1); + } + /* Provide a string identifier for the given image type. */ diff --git a/src/common.h b/src/common.h index 74dff0e08..3888f3f2b 100644 --- a/src/common.h +++ b/src/common.h @@ -182,6 +182,11 @@ namespace sharp { bool IsDzZip(std::string const &str); bool IsV(std::string const &str); + /* + Trim space from end of string. + */ + std::string TrimEnd(std::string const &str); + /* Provide a string identifier for the given image type. */ diff --git a/src/metadata.cc b/src/metadata.cc index 67e67e2de..4cd2ed8d7 100644 --- a/src/metadata.cc +++ b/src/metadata.cc @@ -247,7 +247,7 @@ class MetadataWorker : public Napi::AsyncWorker { } Callback().MakeCallback(Receiver().Value(), { env.Null(), info }); } else { - Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, baton->err).Value() }); + Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() }); } delete baton->input; diff --git a/src/pipeline.cc b/src/pipeline.cc index 7f8820036..78c01e4d8 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -1234,7 +1234,7 @@ class PipelineWorker : public Napi::AsyncWorker { Callback().MakeCallback(Receiver().Value(), { env.Null(), info }); } } else { - Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, baton->err).Value() }); + Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() }); } // Delete baton diff --git a/src/stats.cc b/src/stats.cc index a359319d3..c6c0ccc08 100644 --- a/src/stats.cc +++ b/src/stats.cc @@ -143,7 +143,7 @@ class StatsWorker : public Napi::AsyncWorker { info.Set("dominant", dominant); Callback().MakeCallback(Receiver().Value(), { env.Null(), info }); } else { - Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, baton->err).Value() }); + Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() }); } delete baton->input; diff --git a/test/unit/extract.js b/test/unit/extract.js index f69f584f1..760e90ef7 100644 --- a/test/unit/extract.js +++ b/test/unit/extract.js @@ -293,7 +293,7 @@ describe('Partial image extraction', function () { .extract({ left: 3000, top: 10, width: 10, height: 10 }) .toBuffer(function (err) { assert(err instanceof Error); - assert.strictEqual(err.message, 'extract_area: bad extract area\n'); + assert.strictEqual(err.message, 'extract_area: bad extract area'); done(); }); });