Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/commands/sourcemaps/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,18 @@ fn fetch_release_artifacts(org: &str, project: &str, release: &str) -> Result<Ve
})?
}

/*
* Try to find an artifact which matches the path part of the url extracted from the stacktrace frame,
* prefixed with the default `~/`, which is a "glob-like" pattern for matchin any hostname.
*
* We only need the `pathname` portion of the url, so if it's absolute, just extract it.
* If it's relative however, parse any random url (example.com) and join it with our relative url,
* as Rust cannot handle parsing of relative urls.
*
* http://localhost:5000/dist/bundle.min.js => ~/dist/bundle.min.js
* /dist/bundle.js.map => ~/dist/bundle.js.map
* okboomer => error (invalid relative path, no extension)
*
* It should be more generic than using the defaults, but should be sufficient for our current usecase.
*/
// Try to find an artifact which matches the path part of the url extracted from the stacktrace frame,
// prefixed with the default `~/`, which is a "glob-like" pattern for matchin any hostname.
//
// We only need the `pathname` portion of the url, so if it's absolute, just extract it.
// If it's relative however, parse any random url (example.com) and join it with our relative url,
// as Rust cannot handle parsing of relative urls.
//
// http://localhost:5000/dist/bundle.min.js => ~/dist/bundle.min.js
// /dist/bundle.js.map => ~/dist/bundle.js.map
// okboomer => error (invalid relative path, no extension)
//
// It should be more generic than using the defaults, but should be sufficient for our current usecase.
fn find_matching_artifact(artifacts: &[Artifact], abs_path: &str) -> Result<Artifact> {
let abs_path = match Url::parse(abs_path) {
Ok(path) => Ok(path),
Expand Down
39 changes: 29 additions & 10 deletions src/utils/appcenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use std::str;
use anyhow::{bail, format_err, Error, Result};
use console::strip_ansi_codes;
use glob::{glob_with, MatchOptions};
// use serde::de::{Deserialize, Deserializer, Error as DeError};
use if_chain::if_chain;
use serde::de;
use serde::Deserialize;

use crate::utils::releases::{get_xcode_release_name, infer_gradle_release_name};
use crate::utils::xcode::{InfoPlist, XcodeProjectInfo};
Expand All @@ -34,6 +34,12 @@ pub struct AppCenterPackage {
pub label: String,
}

#[derive(Debug, Deserialize)]
pub struct AppCenterOutput {
#[serde(rename = "errorMessage")]
pub error_message: String,
}

impl<'de> de::Deserialize<'de> for AppCenterPackage {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct PackageVisitor;
Expand Down Expand Up @@ -66,16 +72,29 @@ impl<'de> de::Deserialize<'de> for AppCenterPackage {
}
}

// AppCenter CLI can throw errors in 2 different formats, based on the `--output` flag,
// and we want to handle them both (we call it with `--output json` ourselves).
//
// JSON: `{"succeeded":false,"errorCode":5,"errorMessage":"Command 'appcenter codepush deployment history' requires a logged in user. Use the 'appcenter login' command to log in."}`
// Text: `Error: Command 'appcenter codepush deployment history' requires a logged in user. Use the 'appcenter login' command to log in.`
//
// Also, starting version 2.10.8 (2022-01-10), it prints to `stderr`, where it used to use `stdout` before.
// ref: https://github.com/microsoft/appcenter-cli/commit/b3d6290afcb84affe6a4096893b1ea11d10ac3cf
pub fn get_appcenter_error(output: &Output) -> Error {
let message = str::from_utf8(&output.stdout).unwrap_or("Unknown AppCenter error");

let stripped = strip_ansi_codes(message);
let cause = if let Some(rest) = stripped.strip_prefix("Error: ") {
rest
} else {
&stripped
}
.to_string();
let cause = serde_json::from_slice::<AppCenterOutput>(&output.stderr)
.map(|o| o.error_message)
.unwrap_or_else(|_| {
str::from_utf8(&output.stderr)
.map(|o| {
let stripped = strip_ansi_codes(o);
if let Some(rest) = stripped.strip_prefix("Error: ") {
rest.to_string()
} else {
stripped.to_string()
}
})
.unwrap_or_else(|_| "Unknown AppCenter error".to_string())
});

format_err!(cause)
}
Expand Down