mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* Add startup script logs to the database * Add coderd endpoints for startup script logs * Push startup script logs from agent * Pull startup script logs on frontend * Rename queries * Add constraint * Start creating log sending loop * Add log sending to the agent * Add tests for streaming logs * Shorten notify channel name * Add FE * Improve bulk log performance * Finish UI display * Fix startup log visibility * Add warning for overflow * Fix agent queue logs overflow * Display staartup logs in a virtual DOM for performance * Fix agent queue with loads of logs * Fix authorize test * Remove faulty test * Fix startup and shutdown reporting error * Fix gen * Fix comments * Periodically purge old database entries * Add test fixture for migration * Add Storybook * Check if there are logs when displaying features * Fix startup component overflow gap * Fix startup log wrapping --------- Co-authored-by: Asher <ash@coder.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package database
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
func IsSerializedError(err error) bool {
|
|
var pqErr *pq.Error
|
|
if errors.As(err, &pqErr) {
|
|
return pqErr.Code.Name() == "serialization_failure"
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsUniqueViolation checks if the error is due to a unique violation.
|
|
// If one or more specific unique constraints are given as arguments,
|
|
// the error must be caused by one of them. If no constraints are given,
|
|
// this function returns true for any unique violation.
|
|
func IsUniqueViolation(err error, uniqueConstraints ...UniqueConstraint) bool {
|
|
var pqErr *pq.Error
|
|
if errors.As(err, &pqErr) {
|
|
if pqErr.Code.Name() == "unique_violation" {
|
|
if len(uniqueConstraints) == 0 {
|
|
return true
|
|
}
|
|
for _, uc := range uniqueConstraints {
|
|
if pqErr.Constraint == string(uc) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// IsQueryCanceledError checks if the error is due to a query being canceled.
|
|
func IsQueryCanceledError(err error) bool {
|
|
var pqErr *pq.Error
|
|
if errors.As(err, &pqErr) {
|
|
return pqErr.Code.Name() == "query_canceled"
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func IsStartupLogsLimitError(err error) bool {
|
|
var pqErr *pq.Error
|
|
if errors.As(err, &pqErr) {
|
|
return pqErr.Constraint == "max_startup_logs_length" && pqErr.Table == "workspace_agents"
|
|
}
|
|
|
|
return false
|
|
}
|