Skip to content

refactor: Improve error log message when manifest.json is empty - #1667

Open
d3xter666 wants to merge 5 commits into
mainfrom
refactor-manifest-messages
Open

d3xter666 wants to merge 5 commits into
mainfrom
refactor-manifest-messages

Conversation

@d3xter666

Copy link
Copy Markdown
Member

JIRA: CPOUI5FOUNDATION-1046

Comment thread packages/builder/lib/utils/json.js Outdated
@d3xter666
d3xter666 force-pushed the refactor-manifest-messages branch 2 times, most recently from 15d0eb5 to 2e094a7 Compare October 20, 2026 07:06
Extend the parseJSON helper in project and builder packages to use
try/catch around JSON.parse, distinguishing empty content (ERR_EMPTY_JSON)
from malformed content (ERR_INVALID_JSON, thrown as SyntaxError).

Update manifest readers in Application and Component to re-throw
ERR_INVALID_JSON unwrapped, so the file path is preserved in the message
shown to users instead of being hidden behind a generic "Failed to read"
wrapper.
@d3xter666
d3xter666 force-pushed the refactor-manifest-messages branch from 2e094a7 to 85ac842 Compare October 20, 2026 07:50
@d3xter666
d3xter666 requested a review from RandomByte October 20, 2026 08:57
Comment thread packages/project/lib/specifications/types/Application.js Outdated
return parseJSON(await resource.getString(), `${this._webappPath}${filePath}`);
}).catch((err) => {
if (err.code === "ENOENT") {
if (err.code === "ENOENT" || err.code === "ERR_EMPTY_JSON" || err.code === "ERR_INVALID_JSON") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thinking about this more (and looking at the tests), isn't it problematic that the error no longer mentions the project name now?

@d3xter666 d3xter666 Oct 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have refactored it not to handle these special cases: e9b7e4e
Now the error handler below will throw them along with its message specifying the project name.

There's a bit redundancy here, but I see this pattern is ok from the code I see in

if (namespace) {
this._log.verbose(
`Found namespace ${namespace} in .library file of project ${this.getName()} ` +
`at ${filePath}`);
return {
namespace,
filePath
};
} else {
throw new Error(
`No library name found in .library of project ${this.getName()} ` +
`at ${filePath}`);
}
} catch (err) {
this._log.verbose(
`Namespace resolution from .library failed for project ` +
`${this.getName()}: ${err.message}`);
}

I would appreciate if you have any ideas on how to handle this better and more generic.

return JSON.parse(await resource.getString());
return parseJSON(await resource.getString(), `${this._srcPath}${filePath}`);
}).catch((err) => {
// Do not handle parseJSON's exceptions independently since some information will be lost.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this comment is really not wrong, it seems to be documenting code that is not there (anymore).

I find that a bit confusing? Does it really help, without knowing the history of this PR, or should we rather remove it?

}).catch((err) => {
// Do not handle parseJSON's exceptions independently since some information will be lost.
// See the Error below
if (err.code === "ENOENT") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now you added this new if clause for Component.js. That's fine (although I thought you wanted to do that rather in a future change?) - but then we should also add it in Library.js

This branch has not been deployed

No deployments
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.

2 participants