fn from_json()

in ingester/lib/src/signature.rs [119:168]


    fn from_json(json: &'a str) -> Option<Self> {
        let exception = match serde_json::from_str::<Option<json::JavaException>>(json) {
            Err(e) => {
                log::error!("failed to deserialize java exception: {e}");
                None
            }
            Ok(v) => v,
        }?;

        let mut module: Option<String> = None;
        let mut exc_type: Option<String> = None;

        let mut parse_exception = |s: &str| {
            let mut iter = s.rsplitn(2, ".");
            exc_type = iter.next().map(ToOwned::to_owned);
            module = iter.next().map(ToOwned::to_owned);
        };

        let frames;
        match exception {
            json::JavaException::V0 { messages, stack } => {
                // Try to get exception name from the messages.
                let first_message = messages.into_iter().nth(0);
                if let Some((front, _)) = first_message.as_ref().and_then(|m| m.split_once(":")) {
                    if front.ends_with("Exception") {
                        parse_exception(front);
                    }
                }
                frames = stack;
            }
            json::JavaException::V1 { throwables } => {
                if let Some(first) = throwables.into_iter().nth(0) {
                    parse_exception(&first.type_name);
                    frames = first.stack;
                } else {
                    frames = Default::default();
                }
            }
        }

        Some(JavaException {
            exception: Exception {
                values: vec![ExceptionValue::Stacktrace {
                    module,
                    exc_type,
                    frames,
                }],
            },
        })
    }