Add clock drift error messages to 14 more implementations
When timestamp auth fails (401 with timestamp in error), show helpful message: - Error: Request timestamp expired (must be within 5 minutes of server time) - Your computer's clock may have drifted. - NTP sync commands for Linux/macOS/Windows Updated: un.awk, un.cpp, un.cr, un.d, un.dart, un.groovy, un.jl, un.kt, un.nim, un.ps1, un.rs, un.tcl, un.ts, un.v
This commit is contained in:
parent
ae8f9ee8c8
commit
bc0da08a08
14 changed files with 168 additions and 9 deletions
11
un.awk
11
un.awk
|
|
@ -169,6 +169,17 @@ function execute(filename , api_key) {
|
|||
# Clean up
|
||||
system("rm -f " tmp)
|
||||
|
||||
# Check for timestamp authentication errors
|
||||
if (match(response, /timestamp/) && (match(response, /401/) || match(response, /expired/) || match(response, /invalid/))) {
|
||||
print RED "Error: Request timestamp expired (must be within 5 minutes of server time)" RESET > "/dev/stderr"
|
||||
print YELLOW "Your computer's clock may have drifted." RESET > "/dev/stderr"
|
||||
print "Check your system time and sync with NTP if needed:" > "/dev/stderr"
|
||||
print " Linux: sudo ntpdate -s time.nist.gov" > "/dev/stderr"
|
||||
print " macOS: sudo sntp -sS time.apple.com" > "/dev/stderr"
|
||||
print " Windows: w32tm /resync" > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Parse stdout from response (simple regex)
|
||||
if (match(response, /"stdout":"([^"]*)"/, arr)) {
|
||||
stdout = arr[1]
|
||||
|
|
|
|||
13
un.cpp
13
un.cpp
|
|
@ -109,6 +109,19 @@ string exec_curl(const string& cmd) {
|
|||
result += buffer;
|
||||
}
|
||||
pclose(pipe);
|
||||
|
||||
// Check for timestamp authentication errors
|
||||
if (result.find("timestamp") != string::npos &&
|
||||
(result.find("401") != string::npos || result.find("expired") != string::npos || result.find("invalid") != string::npos)) {
|
||||
cerr << RED << "Error: Request timestamp expired (must be within 5 minutes of server time)" << RESET << endl;
|
||||
cerr << YELLOW << "Your computer's clock may have drifted." << RESET << endl;
|
||||
cerr << "Check your system time and sync with NTP if needed:" << endl;
|
||||
cerr << " Linux: sudo ntpdate -s time.nist.gov" << endl;
|
||||
cerr << " macOS: sudo sntp -sS time.apple.com" << endl;
|
||||
cerr << " Windows: w32tm /resync" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
12
un.cr
12
un.cr
|
|
@ -130,7 +130,17 @@ def api_request(endpoint : String, public_key : String, secret_key : String?, me
|
|||
|
||||
JSON.parse(response.body)
|
||||
rescue ex
|
||||
STDERR.puts "#{RED}Error: Request failed: #{ex.message}#{RESET}"
|
||||
error_msg = ex.message || ""
|
||||
if error_msg.downcase.includes?("timestamp") || (response && response.status_code == 401 && response.body.downcase.includes?("timestamp"))
|
||||
STDERR.puts "#{RED}Error: Request timestamp expired (must be within 5 minutes of server time)#{RESET}"
|
||||
STDERR.puts "#{YELLOW}Your computer's clock may have drifted.#{RESET}"
|
||||
STDERR.puts "Check your system time and sync with NTP if needed:"
|
||||
STDERR.puts " Linux: sudo ntpdate -s time.nist.gov"
|
||||
STDERR.puts " macOS: sudo sntp -sS time.apple.com"
|
||||
STDERR.puts " Windows: w32tm /resync"
|
||||
else
|
||||
STDERR.puts "#{RED}Error: Request failed: #{ex.message}#{RESET}"
|
||||
end
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
|
|
|
|||
17
un.d
17
un.d
|
|
@ -121,7 +121,22 @@ string buildAuthHeaders(string method, string path, string body, string publicKe
|
|||
|
||||
string execCurl(string cmd) {
|
||||
auto result = executeShell(cmd);
|
||||
return result.output;
|
||||
string output = result.output;
|
||||
|
||||
// Check for timestamp authentication errors
|
||||
import std.algorithm : canFind;
|
||||
if (output.canFind("timestamp") &&
|
||||
(output.canFind("401") || output.canFind("expired") || output.canFind("invalid"))) {
|
||||
stderr.writefln("%sError: Request timestamp expired (must be within 5 minutes of server time)%s", RED, RESET);
|
||||
stderr.writefln("%sYour computer's clock may have drifted.%s", YELLOW, RESET);
|
||||
stderr.writeln("Check your system time and sync with NTP if needed:");
|
||||
stderr.writeln(" Linux: sudo ntpdate -s time.nist.gov");
|
||||
stderr.writeln(" macOS: sudo sntp -sS time.apple.com");
|
||||
stderr.writeln(" Windows: w32tm /resync");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void cmdExecute(string sourceFile, string[] envs, bool artifacts, string network, int vcpu, string publicKey, string secretKey) {
|
||||
|
|
|
|||
13
un.dart
13
un.dart
|
|
@ -172,6 +172,19 @@ Future<Map<String, dynamic>> apiRequestCurl(String endpoint, String method, Stri
|
|||
}
|
||||
|
||||
final response = result.stdout as String;
|
||||
|
||||
// Check for timestamp authentication errors
|
||||
if (response.toLowerCase().contains('timestamp') &&
|
||||
(response.contains('401') || response.toLowerCase().contains('expired') || response.toLowerCase().contains('invalid'))) {
|
||||
stderr.writeln('${red}Error: Request timestamp expired (must be within 5 minutes of server time)$reset');
|
||||
stderr.writeln('${yellow}Your computer\'s clock may have drifted.$reset');
|
||||
stderr.writeln('Check your system time and sync with NTP if needed:');
|
||||
stderr.writeln(' Linux: sudo ntpdate -s time.nist.gov');
|
||||
stderr.writeln(' macOS: sudo sntp -sS time.apple.com');
|
||||
stderr.writeln(' Windows: w32tm /resync');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return jsonDecode(response) as Map<String, dynamic>;
|
||||
} finally {
|
||||
await tempFile.delete();
|
||||
|
|
|
|||
12
un.groovy
12
un.groovy
|
|
@ -168,6 +168,18 @@ def apiRequest(endpoint, method, data, publicKey, secretKey) {
|
|||
System.exit(1)
|
||||
}
|
||||
|
||||
// Check for timestamp authentication errors
|
||||
if (output.toLowerCase().contains('timestamp') &&
|
||||
(output.contains('401') || output.toLowerCase().contains('expired') || output.toLowerCase().contains('invalid'))) {
|
||||
System.err.println("${RED}Error: Request timestamp expired (must be within 5 minutes of server time)${RESET}")
|
||||
System.err.println("${YELLOW}Your computer's clock may have drifted.${RESET}")
|
||||
System.err.println("Check your system time and sync with NTP if needed:")
|
||||
System.err.println(" Linux: sudo ntpdate -s time.nist.gov")
|
||||
System.err.println(" macOS: sudo sntp -sS time.apple.com")
|
||||
System.err.println(" Windows: w32tm /resync")
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
return output
|
||||
} finally {
|
||||
tempFile.delete()
|
||||
|
|
|
|||
12
un.jl
12
un.jl
|
|
@ -141,7 +141,17 @@ function api_request(endpoint::String, public_key::String, secret_key::String; m
|
|||
return JSON.parse(String(response.body))
|
||||
catch e
|
||||
if isa(e, HTTP.ExceptionRequest.StatusError)
|
||||
println(stderr, "$(RED)Error: HTTP $(e.status) - $(String(e.response.body))$(RESET)")
|
||||
error_body = String(e.response.body)
|
||||
if e.status == 401 && occursin("timestamp", lowercase(error_body))
|
||||
println(stderr, "$(RED)Error: Request timestamp expired (must be within 5 minutes of server time)$(RESET)")
|
||||
println(stderr, "$(YELLOW)Your computer's clock may have drifted.$(RESET)")
|
||||
println(stderr, "Check your system time and sync with NTP if needed:")
|
||||
println(stderr, " Linux: sudo ntpdate -s time.nist.gov")
|
||||
println(stderr, " macOS: sudo sntp -sS time.apple.com")
|
||||
println(stderr, " Windows: w32tm /resync")
|
||||
else
|
||||
println(stderr, "$(RED)Error: HTTP $(e.status) - $(error_body)$(RESET)")
|
||||
end
|
||||
else
|
||||
println(stderr, "$(RED)Error: Request failed: $e$(RESET)")
|
||||
end
|
||||
|
|
|
|||
9
un.kt
9
un.kt
|
|
@ -530,6 +530,15 @@ fun apiRequest(endpoint: String, method: String, data: Map<String, Any>?, public
|
|||
|
||||
if (connection.responseCode !in 200..299) {
|
||||
val error = connection.errorStream?.bufferedReader()?.readText() ?: ""
|
||||
if (connection.responseCode == 401 && error.lowercase().contains("timestamp")) {
|
||||
System.err.println("${RED}Error: Request timestamp expired (must be within 5 minutes of server time)${RESET}")
|
||||
System.err.println("${YELLOW}Your computer's clock may have drifted.${RESET}")
|
||||
System.err.println("Check your system time and sync with NTP if needed:")
|
||||
System.err.println(" Linux: sudo ntpdate -s time.nist.gov")
|
||||
System.err.println(" macOS: sudo sntp -sS time.apple.com")
|
||||
System.err.println(" Windows: w32tm /resync")
|
||||
exitProcess(1)
|
||||
}
|
||||
throw RuntimeException("HTTP ${connection.responseCode} - $error")
|
||||
}
|
||||
|
||||
|
|
|
|||
11
un.nim
11
un.nim
|
|
@ -98,6 +98,17 @@ proc buildAuthHeaders(meth: string, path: string, body: string, publicKey: strin
|
|||
proc execCurl(cmd: string): string =
|
||||
result = execProcess(cmd)
|
||||
|
||||
# Check for timestamp authentication errors
|
||||
if result.contains("timestamp") and
|
||||
(result.contains("401") or result.contains("expired") or result.contains("invalid")):
|
||||
stderr.writeLine(RED & "Error: Request timestamp expired (must be within 5 minutes of server time)" & RESET)
|
||||
stderr.writeLine(YELLOW & "Your computer's clock may have drifted." & RESET)
|
||||
stderr.writeLine("Check your system time and sync with NTP if needed:")
|
||||
stderr.writeLine(" Linux: sudo ntpdate -s time.nist.gov")
|
||||
stderr.writeLine(" macOS: sudo sntp -sS time.apple.com")
|
||||
stderr.writeLine(" Windows: w32tm /resync")
|
||||
quit(1)
|
||||
|
||||
proc cmdExecute(sourceFile: string, envs: seq[string], artifacts: bool, network: string, vcpu: int, publicKey: string, secretKey: string) =
|
||||
let lang = detectLanguage(sourceFile)
|
||||
if lang == "":
|
||||
|
|
|
|||
12
un.ps1
12
un.ps1
|
|
@ -111,7 +111,17 @@ function Invoke-Api {
|
|||
}
|
||||
return $response
|
||||
} catch {
|
||||
Write-Error "Error: $($_.Exception.Message)"
|
||||
$errorMsg = $_.Exception.Message
|
||||
if ($errorMsg -match "401" -and $errorMsg -match "timestamp") {
|
||||
Write-Host "`e[31mError: Request timestamp expired (must be within 5 minutes of server time)`e[0m" -ForegroundColor Red
|
||||
Write-Host "`e[33mYour computer's clock may have drifted.`e[0m" -ForegroundColor Yellow
|
||||
Write-Host "Check your system time and sync with NTP if needed:"
|
||||
Write-Host " Linux: sudo ntpdate -s time.nist.gov"
|
||||
Write-Host " macOS: sudo sntp -sS time.apple.com"
|
||||
Write-Host " Windows: w32tm /resync"
|
||||
} else {
|
||||
Write-Error "Error: $errorMsg"
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
un.rs
15
un.rs
|
|
@ -228,7 +228,20 @@ fn api_request(endpoint: &str, method: &str, body: Option<&str>, public_key: &st
|
|||
process::exit(1);
|
||||
}
|
||||
|
||||
String::from_utf8_lossy(&output.stdout).to_string()
|
||||
let result = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
||||
// Check for timestamp authentication errors
|
||||
if result.contains("timestamp") && (result.contains("401") || result.contains("expired") || result.contains("invalid")) {
|
||||
eprintln!("{}Error: Request timestamp expired (must be within 5 minutes of server time){}", RED, RESET);
|
||||
eprintln!("{}Your computer's clock may have drifted.{}", YELLOW, RESET);
|
||||
eprintln!("Check your system time and sync with NTP if needed:");
|
||||
eprintln!(" Linux: sudo ntpdate -s time.nist.gov");
|
||||
eprintln!(" macOS: sudo sntp -sS time.apple.com");
|
||||
eprintln!(" Windows: w32tm /resync");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn cmd_execute(
|
||||
|
|
|
|||
13
un.tcl
13
un.tcl
|
|
@ -151,8 +151,17 @@ proc api_request {endpoint method data public_key secret_key} {
|
|||
::http::cleanup $token
|
||||
|
||||
if {$status ne "ok" || ($ncode != 200 && $ncode != 201)} {
|
||||
puts stderr "${::RED}Error: HTTP $ncode${::RESET}"
|
||||
puts stderr $body
|
||||
if {$ncode == 401 && [string match -nocase "*timestamp*" $body]} {
|
||||
puts stderr "${::RED}Error: Request timestamp expired (must be within 5 minutes of server time)${::RESET}"
|
||||
puts stderr "${::YELLOW}Your computer's clock may have drifted.${::RESET}"
|
||||
puts stderr "Check your system time and sync with NTP if needed:"
|
||||
puts stderr " Linux: sudo ntpdate -s time.nist.gov"
|
||||
puts stderr " macOS: sudo sntp -sS time.apple.com"
|
||||
puts stderr " Windows: w32tm /resync"
|
||||
} else {
|
||||
puts stderr "${::RED}Error: HTTP $ncode${::RESET}"
|
||||
puts stderr $body
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
|
|||
11
un.ts
11
un.ts
|
|
@ -191,7 +191,16 @@ function apiRequest(endpoint: string, method: string = "GET", data: any = null,
|
|||
resolve(body);
|
||||
}
|
||||
} else {
|
||||
console.error(`${RED}Error: HTTP ${res.statusCode} - ${body}${RESET}`);
|
||||
if (res.statusCode === 401 && body.toLowerCase().includes('timestamp')) {
|
||||
console.error(`${RED}Error: Request timestamp expired (must be within 5 minutes of server time)${RESET}`);
|
||||
console.error(`${YELLOW}Your computer's clock may have drifted.${RESET}`);
|
||||
console.error("Check your system time and sync with NTP if needed:");
|
||||
console.error(" Linux: sudo ntpdate -s time.nist.gov");
|
||||
console.error(" macOS: sudo sntp -sS time.apple.com");
|
||||
console.error(" Windows: w32tm /resync");
|
||||
} else {
|
||||
console.error(`${RED}Error: HTTP ${res.statusCode} - ${body}${RESET}`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
16
un.v
16
un.v
|
|
@ -97,7 +97,21 @@ fn escape_json(s string) string {
|
|||
|
||||
fn exec_curl(cmd string) string {
|
||||
result := os.execute(cmd)
|
||||
return result.output
|
||||
output := result.output
|
||||
|
||||
// Check for timestamp authentication errors
|
||||
if output.contains('timestamp') &&
|
||||
(output.contains('401') || output.contains('expired') || output.contains('invalid')) {
|
||||
eprintln('${red}Error: Request timestamp expired (must be within 5 minutes of server time)${reset}')
|
||||
eprintln('${yellow}Your computer\'s clock may have drifted.${reset}')
|
||||
eprintln('Check your system time and sync with NTP if needed:')
|
||||
eprintln(' Linux: sudo ntpdate -s time.nist.gov')
|
||||
eprintln(' macOS: sudo sntp -sS time.apple.com')
|
||||
eprintln(' Windows: w32tm /resync')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
fn extract_json_string(json string, key string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue