Skip to content

protect against empty config from quarto inspect#961

Merged
cscheid merged 2 commits intomainfrom
bugfix/issue-958
May 2, 2026
Merged

protect against empty config from quarto inspect#961
cscheid merged 2 commits intomainfrom
bugfix/issue-958

Conversation

@cscheid
Copy link
Copy Markdown
Member

@cscheid cscheid commented May 2, 2026

This PR reconciles output types with quarto-cli and protects against empty config in quarto inspect.

There's so many code smells in this file, it's all a bit terrifying. But this is a localized fix.

Closes #958.

@posit-snyk-bot
Copy link
Copy Markdown
Contributor

posit-snyk-bot commented May 2, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cscheid cscheid requested a review from juliasilge May 2, 2026 17:46
@cscheid
Copy link
Copy Markdown
Member Author

cscheid commented May 2, 2026

(This file was not canonically formatted before now, so there's some diff churn, apologies.)

The important lines changed are

line 115

Add ? to the field QuartoProjectConfig.files.config:

export type QuartoProjectConfig = {
  dir: string;
  config: {
    project: {
      type: string;
      preview: {
        serve: { /* */ };
      };
    };
    format: Record<string, unknown> | string;
    [key: string]: unknown;
  };
  files: {
    input: string[];
    config?: string[];
  };
};

Clearly what should have happened all along is that quarto-cli and quarto both use the exact same type declarations. Alas, this will all go away in the land of Quarto 2 anyway.

line 274

from config.files.config.reduce to (config.files.config ?? []).reduce:

function configHash(config: QuartoProjectConfig) {
  return (config.files.config ?? []).reduce((hash, file) => {
    return hash + fs.statSync(file).mtimeMs.toLocaleString();
  }, "");
}

Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

It took me a bit here to understand why this is biting us in some situations now, when this code hasn't been changed in years. Here is what I understand:

Quarto 1.9.37 changed quarto inspect <file> so that even files outside any project now get a "project" block in the output. Now, if you have a situation where you have:

  • No _quarto.yml anywhere up the directory tree
  • A .qmd with no YAML front matter

Then you end up on the code path where this crash happens and this bug gets exposed. The change in Quarto 1.9.37 brought this code path into use, when it never was before.

Thanks for finding the problem, @cscheid! 🙌

@juliasilge
Copy link
Copy Markdown
Collaborator

@cscheid I think we should add this to the extension CHANGELOG even though it is not technically in extension code. Can you add that before merging?

@cscheid cscheid merged commit 6077276 into main May 2, 2026
4 checks passed
@juliasilge juliasilge deleted the bugfix/issue-958 branch May 4, 2026 17:07
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.

Quarto CLI 1.9.37 breaks extension with message "TypeError: Cannot read properties of undefined (reading 'reduce') "

3 participants