@@ -94,10 +94,10 @@ func (logCmd *LogCmd) RunE(_ *cobra.Command, args []string) (err error) {
9494 if * logCmd .scope .workspaceId == 0 {
9595 * logCmd .scope .workspaceId , err = strconv .Atoi (os .Getenv ("CS_WORKSPACE_ID" ))
9696 if err != nil {
97- return fmt .Errorf ("Failed to read env var: %e" , err )
97+ return fmt .Errorf ("failer to read env var: %e" , err )
9898 }
9999 if * logCmd .scope .workspaceId == 0 {
100- return errors .New ("Workspace ID required, but not provided. " )
100+ return errors .New ("workspace ID required, but not provided" )
101101 }
102102 }
103103
@@ -119,9 +119,9 @@ func (logCmd *LogCmd) RunE(_ *cobra.Command, args []string) (err error) {
119119 return printLogsOfServer (& logCmd .scope )
120120 }
121121
122- logCmd .printAllLogs ()
122+ err = logCmd .printAllLogs ()
123123 if err != nil {
124- return fmt .Errorf ("Failed to print logs: %e" , err )
124+ return fmt .Errorf ("failed to print logs: %e" , err )
125125 }
126126
127127 return nil
@@ -132,20 +132,23 @@ func (l *LogCmd) printAllLogs() error {
132132
133133 replicas , err := cs .GetPipelineStatus (* l .scope .workspaceId , "run" )
134134 if err != nil {
135- return fmt .Errorf ("Failed to get pipeline status: %e" , err )
135+ return fmt .Errorf ("failed to get pipeline status: %e" , err )
136136 }
137137
138138 var wg sync.WaitGroup
139139 for _ , replica := range replicas {
140- for s , _ := range replica .Steps {
140+ for s := range replica .Steps {
141141 wg .Add (1 )
142142 go func () {
143143 defer wg .Done ()
144144 scope := l .scope
145145 * scope .step = s
146146 * scope .replica = replica .Replica
147147 prefix := fmt .Sprintf ("|%-10s|%s" , replica .Server , replica .Replica [len (replica .Replica )- 11 :])
148- printLogsOfReplica (prefix , & scope )
148+ err = printLogsOfReplica (prefix , & scope )
149+ if err != nil {
150+ fmt .Printf ("Error printling logs: %e\n " , err )
151+ }
149152 }()
150153 }
151154 }
@@ -183,21 +186,24 @@ func printLogsOfEndpoint(prefix string, endpoint string) error {
183186
184187 req , err := http .NewRequestWithContext (ctx , "GET" , endpoint , nil )
185188 if err != nil {
186- return fmt .Errorf ("Failed to construct request: %s" , err )
189+ return fmt .Errorf ("failed to construct request: %s" , err )
187190 }
188191
189192 // Set the Accept header to indicate SSE
190193 req .Header .Set ("Accept" , "text/event-stream" )
191- cs .SetAuthoriziationHeader (req )
194+ err = cs .SetAuthoriziationHeader (req )
195+ if err != nil {
196+ return fmt .Errorf ("failed to set header: %e" , err )
197+ }
192198
193199 resp , err := http .DefaultClient .Do (req )
194200 if err != nil {
195- return fmt .Errorf ("Failed to request logs: %s " , err )
201+ return fmt .Errorf ("failed to request logs: %e " , err )
196202 }
197- defer resp .Body .Close ()
203+ defer func () { _ = resp .Body .Close () } ()
198204
199205 if resp .StatusCode != http .StatusOK {
200- return fmt .Errorf ("Log server responded with non-ok code: %d" , resp .StatusCode )
206+ return fmt .Errorf ("log server responded with non-ok code: %d" , resp .StatusCode )
201207 }
202208
203209 reader := bufio .NewReader (resp .Body )
@@ -210,7 +216,7 @@ func printLogsOfEndpoint(prefix string, endpoint string) error {
210216 if err == io .EOF {
211217 return nil
212218 }
213- return fmt .Errorf ("Failed to parse log: %s" , err )
219+ return fmt .Errorf ("failed to parse log: %s" , err )
214220 }
215221
216222 line = strings .TrimSpace (line )
@@ -247,9 +253,12 @@ func printLogsOfEndpoint(prefix string, endpoint string) error {
247253 err := json .Unmarshal ([]byte (sse .data ), & log )
248254 if err != nil {
249255 var errRes ErrResponse
250- json .Unmarshal ([]byte (sse .data ), & errRes )
256+ err = json .Unmarshal ([]byte (sse .data ), & errRes )
257+ if err != nil {
258+ return fmt .Errorf ("error reading error json: %e" , err )
259+ }
251260 return fmt .Errorf (
252- "Server responded with error: %d %s: %s" ,
261+ "server responded with error: %d %s: %s" ,
253262 errRes .Status , errRes .Title , errRes .Detail ,
254263 )
255264 }
0 commit comments