`v8.writeHeapSnapshot` may return `undefined` if the file fails to write

Version

v16.13.1

Platform

Linux bd035f8a23f8 4.19.0-18-amd64 # 1 SMP Debian 4.19.208-1 (2021-09-29) x86_64 GNU/Linux

Subsystem

v8

What steps will reproduce the bug?

Call v8.writeHeapSnapshot() on a folder where the process has no permissions to write to (e.g. inside a Docker container, example dockerfile below).

Sample files

package.json

{
    "main": "index.js",
    "scripts": {
        "start": "node ."
    }
}

Dockerfile

FROM node:16-buster-slim

WORKDIR /usr/src/app

COPY --chown=node:node package.json .
COPY --chown=node:node index.js .

USER node

CMD [ "npm", "run-script", "start" ]

This will cause the following code, which returns early (and thus, returning undefined):

if (!WriteSnapshot(isolate, *path))
return;

As the code the line below (which sets the return value) is not executed:

return args.GetReturnValue().Set(filename_v);

How often does it reproduce? Is there a required condition?

Always, requires the module to attempt to write in a folder without write permissions.

What is the expected behavior?

Either to throw an error (permissions error, out of space, etc) or to document that it may return undefined

What do you see instead?

The documentation specifies that it returns a string and does not mention that it may return undefined.

Additional information

No response