From ede837b6873a4f475b66bb6ee44e7190cd404012 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 18 Feb 2022 11:36:53 +0300 Subject: refactor(journaldriver): Use anyhow instead of failure Apparently failure is not hip anymore, and crate updates are forcing the use of anyhow now. Whatever. The functionality basically stays the same, maybe error messages will look a little bit different now. Change-Id: I173d644688785339c16161ddeec47a534123710f Reviewed-on: https://cl.tvl.fyi/c/depot/+/5307 Tested-by: BuildkiteCI Reviewed-by: sterni Autosubmit: tazjin --- ops/journaldriver/src/main.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'ops/journaldriver/src') diff --git a/ops/journaldriver/src/main.rs b/ops/journaldriver/src/main.rs index 0c0e5cc23bff..1315d49eff49 100644 --- a/ops/journaldriver/src/main.rs +++ b/ops/journaldriver/src/main.rs @@ -32,7 +32,7 @@ //! `LOG_NAME` environment variables. #[macro_use] -extern crate failure; +extern crate anyhow; #[macro_use] extern crate log; #[macro_use] @@ -49,9 +49,9 @@ extern crate serde; extern crate systemd; extern crate ureq; +use anyhow::{Context, Result}; use chrono::offset::LocalResult; use chrono::prelude::{DateTime, TimeZone, Utc}; -use failure::ResultExt; use serde_json::{from_str, Value}; use std::fs::{self, rename, File}; use std::io::{self, ErrorKind, Read, Write}; @@ -72,9 +72,6 @@ const METADATA_ZONE_URL: &str = "http://metadata.google.internal/computeMetadata const METADATA_PROJECT_URL: &str = "http://metadata.google.internal/computeMetadata/v1/project/project-id"; -/// Convenience type alias for results using failure's `Error` type. -type Result = std::result::Result; - /// Representation of static service account credentials for GCP. #[derive(Debug, Deserialize)] struct Credentials { @@ -158,8 +155,7 @@ fn get_metadata(url: &str) -> Result { /// Convenience helper for determining the project ID. fn get_project_id() -> String { env::var("GOOGLE_CLOUD_PROJECT") - .map_err(Into::into) - .or_else(|_: failure::Error| get_metadata(METADATA_PROJECT_URL)) + .or_else(|_| get_metadata(METADATA_PROJECT_URL)) .expect("Could not determine project ID") } -- cgit 1.4.1