Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d42ddc06ba | ||
|
|
1a51bf5f96 |
No files matched your search
+18
-10
@@ -42,6 +42,13 @@ fn docker_ps(_verbose: u8) -> Result<()> {
|
||||
.output()
|
||||
.context("Failed to run docker ps")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprint!("{}", stderr);
|
||||
timer.track("docker ps", "rtk docker ps", &raw, &raw);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let mut rtk = String::new();
|
||||
|
||||
@@ -95,6 +102,13 @@ fn docker_images(_verbose: u8) -> Result<()> {
|
||||
.output()
|
||||
.context("Failed to run docker images")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprint!("{}", stderr);
|
||||
timer.track("docker images", "rtk docker images", &raw, &raw);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let lines: Vec<&str> = stdout.lines().collect();
|
||||
let mut rtk = String::new();
|
||||
@@ -204,15 +218,12 @@ fn kubectl_pods(args: &[String], _verbose: u8) -> Result<()> {
|
||||
}
|
||||
};
|
||||
|
||||
let items = json["items"].as_array();
|
||||
if items.is_none() || items.unwrap().is_empty() {
|
||||
let Some(pods) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
rtk.push_str("☸️ No pods found");
|
||||
println!("{}", rtk);
|
||||
timer.track("kubectl get pods", "rtk kubectl pods", &raw, &rtk);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let pods = items.unwrap();
|
||||
};
|
||||
let (mut running, mut pending, mut failed, mut restarts_total) = (0, 0, 0, 0i64);
|
||||
let mut issues: Vec<String> = Vec::new();
|
||||
|
||||
@@ -305,15 +316,12 @@ fn kubectl_services(args: &[String], _verbose: u8) -> Result<()> {
|
||||
}
|
||||
};
|
||||
|
||||
let items = json["items"].as_array();
|
||||
if items.is_none() || items.unwrap().is_empty() {
|
||||
let Some(services) = json["items"].as_array().filter(|a| !a.is_empty()) else {
|
||||
rtk.push_str("☸️ No services found");
|
||||
println!("{}", rtk);
|
||||
timer.track("kubectl get svc", "rtk kubectl svc", &raw, &rtk);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let services = items.unwrap();
|
||||
};
|
||||
rtk.push_str(&format!("☸️ {} services:\n", services.len()));
|
||||
|
||||
for svc in services.iter().take(15) {
|
||||
|
||||
+15
-3
@@ -78,9 +78,21 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
|
||||
&filtered,
|
||||
);
|
||||
|
||||
// golangci-lint returns exit code 1 when issues found (expected behavior)
|
||||
// Don't exit with error code in that case
|
||||
Ok(())
|
||||
// golangci-lint: exit 0 = clean, exit 1 = lint issues, exit 2+ = config/build error
|
||||
// None = killed by signal (OOM, SIGKILL) — always fatal
|
||||
match output.status.code() {
|
||||
Some(0) | Some(1) => Ok(()),
|
||||
Some(code) => {
|
||||
if !stderr.trim().is_empty() {
|
||||
eprintln!("{}", stderr.trim());
|
||||
}
|
||||
std::process::exit(code);
|
||||
}
|
||||
None => {
|
||||
eprintln!("golangci-lint: killed by signal");
|
||||
std::process::exit(130);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Filter golangci-lint JSON output - group by linter and file
|
||||
|
||||
+16
-12
@@ -1,11 +1,23 @@
|
||||
use crate::tracking;
|
||||
use anyhow::Result;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::io::{self, BufRead};
|
||||
use std::path::Path;
|
||||
|
||||
lazy_static! {
|
||||
static ref TIMESTAMP_RE: Regex =
|
||||
Regex::new(r"^\d{4}[-/]\d{2}[-/]\d{2}[T ]\d{2}:\d{2}:\d{2}[.,]?\d*\s*").unwrap();
|
||||
static ref UUID_RE: Regex =
|
||||
Regex::new(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")
|
||||
.unwrap();
|
||||
static ref HEX_RE: Regex = Regex::new(r"0x[0-9a-fA-F]+").unwrap();
|
||||
static ref NUM_RE: Regex = Regex::new(r"\b\d{4,}\b").unwrap();
|
||||
static ref PATH_RE: Regex = Regex::new(r"/[\w./\-]+").unwrap();
|
||||
}
|
||||
|
||||
/// Filter and deduplicate log output
|
||||
pub fn run_file(file: &Path, verbose: u8) -> Result<()> {
|
||||
let timer = tracking::TimedExecution::start();
|
||||
@@ -58,22 +70,14 @@ fn analyze_logs(content: &str) -> String {
|
||||
let mut unique_errors: Vec<String> = Vec::new();
|
||||
let mut unique_warnings: Vec<String> = Vec::new();
|
||||
|
||||
// Patterns to normalize log messages
|
||||
let timestamp_re =
|
||||
Regex::new(r"^\d{4}[-/]\d{2}[-/]\d{2}[T ]\d{2}:\d{2}:\d{2}[.,]?\d*\s*").unwrap();
|
||||
let uuid_re =
|
||||
Regex::new(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")
|
||||
.unwrap();
|
||||
let hex_re = Regex::new(r"0x[0-9a-fA-F]+").unwrap();
|
||||
let num_re = Regex::new(r"\b\d{4,}\b").unwrap();
|
||||
let path_re = Regex::new(r"/[\w./\-]+").unwrap();
|
||||
// Use module-level lazy_static regexes for normalization
|
||||
|
||||
for line in content.lines() {
|
||||
let line_lower = line.to_lowercase();
|
||||
|
||||
// Normalize for deduplication
|
||||
let normalized =
|
||||
normalize_log_line(line, ×tamp_re, &uuid_re, &hex_re, &num_re, &path_re);
|
||||
normalize_log_line(line, &TIMESTAMP_RE, &UUID_RE, &HEX_RE, &NUM_RE, &PATH_RE);
|
||||
|
||||
// Categorize
|
||||
if line_lower.contains("error")
|
||||
@@ -128,7 +132,7 @@ fn analyze_logs(content: &str) -> String {
|
||||
let original = unique_errors
|
||||
.iter()
|
||||
.find(|e| {
|
||||
&normalize_log_line(e, ×tamp_re, &uuid_re, &hex_re, &num_re, &path_re)
|
||||
&normalize_log_line(e, &TIMESTAMP_RE, &UUID_RE, &HEX_RE, &NUM_RE, &PATH_RE)
|
||||
== *normalized
|
||||
})
|
||||
.map(|s| s.as_str())
|
||||
@@ -168,7 +172,7 @@ fn analyze_logs(content: &str) -> String {
|
||||
let original = unique_warnings
|
||||
.iter()
|
||||
.find(|w| {
|
||||
&normalize_log_line(w, ×tamp_re, &uuid_re, &hex_re, &num_re, &path_re)
|
||||
&normalize_log_line(w, &TIMESTAMP_RE, &UUID_RE, &HEX_RE, &NUM_RE, &PATH_RE)
|
||||
== *normalized
|
||||
})
|
||||
.map(|s| s.as_str())
|
||||
|
||||
+4
-1
@@ -43,7 +43,10 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
|
||||
&filtered,
|
||||
);
|
||||
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
if !output.status.success() {
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct MypyError {
|
||||
|
||||
+38
-20
@@ -54,18 +54,24 @@ fn run_generate(args: &[String], verbose: u8) -> Result<()> {
|
||||
.output()
|
||||
.context("Failed to run prisma generate (try: npm install -g prisma)")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
anyhow::bail!("prisma generate failed: {}", stderr);
|
||||
}
|
||||
|
||||
let exit_code = output.status.code().unwrap_or(1);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let raw = format!("{}\n{}", stdout, stderr);
|
||||
|
||||
if !output.status.success() {
|
||||
if !stdout.trim().is_empty() {
|
||||
eprint!("{}", stdout);
|
||||
}
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track("prisma generate", "rtk prisma generate", &raw, &raw);
|
||||
std::process::exit(exit_code);
|
||||
}
|
||||
|
||||
let filtered = filter_prisma_generate(&raw);
|
||||
|
||||
println!("{}", filtered);
|
||||
|
||||
timer.track("prisma generate", "rtk prisma generate", &raw, &filtered);
|
||||
|
||||
Ok(())
|
||||
@@ -105,15 +111,22 @@ fn run_migrate(subcommand: MigrateSubcommand, args: &[String], verbose: u8) -> R
|
||||
|
||||
let output = cmd.output().context("Failed to run prisma migrate")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
anyhow::bail!("prisma migrate failed: {}", stderr);
|
||||
}
|
||||
|
||||
let exit_code = output.status.code().unwrap_or(1);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let raw = format!("{}\n{}", stdout, stderr);
|
||||
|
||||
if !output.status.success() {
|
||||
if !stdout.trim().is_empty() {
|
||||
eprint!("{}", stdout);
|
||||
}
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track(cmd_name, &format!("rtk {}", cmd_name), &raw, &raw);
|
||||
std::process::exit(exit_code);
|
||||
}
|
||||
|
||||
let filtered = match subcommand {
|
||||
MigrateSubcommand::Dev { .. } => filter_migrate_dev(&raw),
|
||||
MigrateSubcommand::Status => filter_migrate_status(&raw),
|
||||
@@ -121,7 +134,6 @@ fn run_migrate(subcommand: MigrateSubcommand, args: &[String], verbose: u8) -> R
|
||||
};
|
||||
|
||||
println!("{}", filtered);
|
||||
|
||||
timer.track(cmd_name, &format!("rtk {}", cmd_name), &raw, &filtered);
|
||||
|
||||
Ok(())
|
||||
@@ -143,18 +155,24 @@ fn run_db_push(args: &[String], verbose: u8) -> Result<()> {
|
||||
|
||||
let output = cmd.output().context("Failed to run prisma db push")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
anyhow::bail!("prisma db push failed: {}", stderr);
|
||||
}
|
||||
|
||||
let exit_code = output.status.code().unwrap_or(1);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let raw = format!("{}\n{}", stdout, stderr);
|
||||
|
||||
if !output.status.success() {
|
||||
if !stdout.trim().is_empty() {
|
||||
eprint!("{}", stdout);
|
||||
}
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track("prisma db push", "rtk prisma db push", &raw, &raw);
|
||||
std::process::exit(exit_code);
|
||||
}
|
||||
|
||||
let filtered = filter_db_push(&raw);
|
||||
|
||||
println!("{}", filtered);
|
||||
|
||||
timer.track("prisma db push", "rtk prisma db push", &raw, &filtered);
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user