Skip to content

output.postProcess execution error is swallowed #3682

@timofei-iatsenko

Description

@timofei-iatsenko

Description

I spent some time investigating why my formatters (prettier or oxfmt) were not working in this setting. Even though the generator command finished successfully without any errors, the code was not being processed by the formatter.

The main problem is that the error from the internal process is "swallowed," making it very difficult to debug why the formatting failed.

Debugging Steps

To find the cause, I had to look into the source code and add manual logging:

const result = sync(resolved.command, args);
const stdout = result.stdout?.toString();
const stderr = result.stderr?.toString();

console.log({ stdout, stderr, result });

The logs revealed that the command was failing because the executable could not be found:

{
"result": {
  "error": "Error: spawnSync oxfmt ENOENT"
}
}

The Cause

The tool oxfmt is installed locally in the project, not globally. Because it is not added to the system PATH, spawnSync cannot find it. I believe it is expected behavior to use the version from the repository, but the generator does not handle this.

Current Workaround

Changing the configuration to use npx solves the issue, as it correctly points to the local node_modules:

postProcess: [
  {
    command: 'npx',
    args: ['oxfmt', '{{path}}'],
  },
],

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Labels

bug 🔥Broken or incorrect behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions