Trim space from end of libvips error messages

This commit is contained in:
Lovell Fuller
2023-03-24 09:58:21 +00:00
parent 0af070ed93
commit b55e58f31e
6 changed files with 16 additions and 4 deletions

View File

@@ -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.
*/

View File

@@ -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.
*/

View File

@@ -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;

View File

@@ -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

View File

@@ -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;