aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs37
-rw-r--r--crates/shirabe/src/console/application.rs10
-rw-r--r--crates/shirabe/src/json/json_file.rs4
3 files changed, 36 insertions, 15 deletions
diff --git a/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs b/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs
index b756c1b..5dca8b6 100644
--- a/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs
+++ b/crates/shirabe-external-packages/src/seld/json_lint/parsing_exception.rs
@@ -1,21 +1,48 @@
+#[derive(Debug, Clone, Default)]
+pub struct ParsingExceptionLoc {
+ pub first_line: i64,
+ pub first_column: i64,
+ pub last_line: i64,
+ pub last_column: i64,
+}
+
+#[derive(Debug, Clone)]
+pub enum ParsingExceptionToken {
+ Name(String),
+ Symbol(i64),
+}
+
+#[derive(Debug, Clone, Default)]
+pub struct ParsingExceptionDetails {
+ pub text: Option<String>,
+ pub token: Option<ParsingExceptionToken>,
+ pub line: Option<i64>,
+ pub loc: Option<ParsingExceptionLoc>,
+ pub expected: Option<Vec<String>>,
+}
+
#[derive(Debug)]
pub struct ParsingException {
pub message: String,
pub code: i64,
+ pub(crate) details: ParsingExceptionDetails,
}
impl ParsingException {
- pub fn new(message: String, _details: Option<shirabe_php_shim::PhpMixed>) -> Self {
- Self { message, code: 0 }
+ pub fn new(message: String, details: ParsingExceptionDetails) -> Self {
+ Self {
+ message,
+ code: 0,
+ details,
+ }
}
pub fn get_message(&self) -> &str {
&self.message
}
- pub fn get_details(&self) -> indexmap::IndexMap<String, shirabe_php_shim::PhpMixed> {
- // TODO(phase-b): PHP ParsingException exposes ['text', 'line', 'token'] details
- indexmap::IndexMap::new()
+ pub fn get_details(&self) -> &ParsingExceptionDetails {
+ &self.details
}
}
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index f27ed79..8bd34ad 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -448,17 +448,11 @@ impl Application {
if e.downcast_ref::<NoSslException>().is_some() {
// suppress these as they are not relevant at this point
} else if let Some(pe) = e.downcast_ref::<ParsingException>() {
- // TODO(phase-b): ParsingException::get_details is not yet ported.
- let details: IndexMap<String, PhpMixed> = IndexMap::new();
+ let details = pe.get_details();
let file = realpath(&Factory::get_composer_file().unwrap_or_default());
- let mut line: Option<i64> = None;
- if !details.is_empty() {
- if let Some(l) = details.get("line").and_then(|v| v.as_int()) {
- line = Some(l);
- }
- }
+ let line = details.line;
let mut ghe = GithubActionError::new(self.io.clone());
ghe.emit(&pe.message, file.as_deref(), line);
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 33496df..0b1b010 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -535,7 +535,7 @@ impl JsonFile {
"The input does not contain valid JSON\n{}",
result.get_message()
),
- None,
+ result.get_details().clone(),
),
Some(f) => ParsingException::new(
format!(
@@ -543,7 +543,7 @@ impl JsonFile {
f,
result.get_message()
),
- None,
+ result.get_details().clone(),
),
}
.into())