Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent exception when passing directory instead of file #3446

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/workerd/server/workerd.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,14 @@ class CliMain final: public SchemaFileImpl::ErrorReporter {
} else {
// Read file from disk.
auto path = fs->getCurrentPath().evalNative(pathStr);

// make sure the path represents a file
KJ_IF_SOME(fsMetadata, fs->getRoot().tryLstat(path)) {
if (fsMetadata.type != kj::FsNode::Type::FILE) {
jmorrell-cloudflare marked this conversation as resolved.
Show resolved Hide resolved
CLI_ERROR("Path is not a file.");
}
}

auto file = KJ_UNWRAP_OR(fs->getRoot().tryOpenFile(path), CLI_ERROR("No such file."));
jmorrell-cloudflare marked this conversation as resolved.
Show resolved Hide resolved

if (binaryConfig) {
Expand Down
Loading