Skip to content

Commit

Permalink
Emit diagnostic for pyproject.toml > 4GB
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed May 22, 2023
1 parent 6b4f600 commit 39f6ff8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crates/ruff/src/pyproject_toml.rs
@@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use anyhow::Result;
use pyproject_toml::PyProjectToml;
use ruff_text_size::{TextRange, TextSize};

Expand All @@ -7,6 +7,7 @@ use ruff_python_ast::source_code::SourceFile;

use crate::message::Message;
use crate::rules::ruff::rules::InvalidPyprojectToml;
use crate::IOError;

pub fn lint_pyproject_toml(source_file: SourceFile) -> Result<Vec<Message>> {
let err = match toml::from_str::<PyProjectToml>(source_file.source_text()) {
Expand All @@ -19,10 +20,26 @@ pub fn lint_pyproject_toml(source_file: SourceFile) -> Result<Vec<Message>> {
// TODO(konstin,micha): https://github.com/charliermarsh/ruff/issues/4571
None => TextRange::default(),
Some(range) => {
let expect_err = "pyproject.toml should be smaller than 4GB";
let end = match TextSize::try_from(range.end) {
Ok(end) => end,
Err(_) => {
let diagnostic = Diagnostic::new(
IOError {
message: format!("pyproject.toml is larger than 4GB"),
},
TextRange::default(),
);
return Ok(vec![Message::from_diagnostic(
diagnostic,
source_file,
TextSize::default(),
)]);
}
};
TextRange::new(
TextSize::try_from(range.start).context(expect_err)?,
TextSize::try_from(range.end).context(expect_err)?,
// start <= end, so if end < 4GB follows start < 4GB
TextSize::try_from(range.start).unwrap(),
end,
)
}
};
Expand Down

0 comments on commit 39f6ff8

Please sign in to comment.