Fallback if toml file parsing failed (#246)

This commit is contained in:
Kevin Stillhammer 2025-01-16 16:54:33 +01:00 committed by GitHub
parent b5f58b2abc
commit 14dc0be27c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 45 additions and 2 deletions

View File

@ -200,3 +200,15 @@ jobs:
exit 1
fi
shell: bash
test-malformed-pyproject-file-fallback:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install using malformed pyproject.toml
id: setup-uv
uses: ./
with:
pyproject-file: "__tests__/fixtures/malformed-pyproject-toml-project/pyproject.toml"
- run: uv sync
working-directory: __tests__/fixtures/uv-project

View File

@ -0,0 +1 @@
3.11

View File

@ -0,0 +1,6 @@
def main():
print("Hello from malformed-pyproject-toml-project!")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,9 @@
[project]
name = "malformed-pyproject-toml-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = []
[malformed-toml

10
dist/setup/index.js generated vendored
View File

@ -99655,7 +99655,15 @@ function getUvVersionFromConfigFile(filePath) {
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
let requiredVersion = getRequiredVersion(filePath);
let requiredVersion;
try {
requiredVersion = getRequiredVersion(filePath);
}
catch (err) {
const message = err.message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
if (requiredVersion?.startsWith("==")) {
requiredVersion = requiredVersion.slice(2);
}

View File

@ -9,7 +9,14 @@ export function getUvVersionFromConfigFile(
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
let requiredVersion = getRequiredVersion(filePath);
let requiredVersion: string | undefined;
try {
requiredVersion = getRequiredVersion(filePath);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
if (requiredVersion?.startsWith("==")) {
requiredVersion = requiredVersion.slice(2);