main.go connects the program to stdin and stdout. app.go scans lines, dispatches commands and writes reports. queue.go owns the map and its rules.
The Tasks method collects copies of records into a fresh slice. slices.SortFunc orders them with cmp.Compare, which puts the smaller ID first. Returning copies lets callers edit the report slice without editing the queue.
New syntax in this project
The project uses a few things that didn't need a lesson of their own. Read these before tracing.
switch verbinexecutepicks the command, as in the Day 5 command lesson. Only the first matchingcaseruns, anddefaultreports an unknown verb.- Named results.
executeis declared asfunc execute(...) (commandErr, writeErr error). The two results have names, which documents which error is which: a rejected command, or a failure to write output. Everyreturnin it still lists both values explicitly, for examplereturn err, nilfor a rejected command. os.Stderris standard error, the third standard stream from the beginner course. It is a writer likeos.Stdout, but meant for problems, so a person can send the report to a file and still see errors on screen.mainwritesrun's error there withfmt.Fprintln(os.Stderr, err).os.Exit(1)ends the program immediately with exit status 1. By convention 0 means success and anything else means failure, which scripts and other tools can check.mainuses it only after printing the error, because nothing afteros.Exitruns, not even deferred code.
Trace a rejected transition
Follow done 7 from input to report. Where is the missing ID detected? Why does a command failure continue the loop, but a read or write failure ends the program?
Hint 1: the idea
Separate an invalid request from a failure of the input or output destination.
Hint 2: a first step
Find the lookup in Finish and follow the two error results returned by execute.
Worked solution
Finish finds no task for 7 and returns an error wrapping errMissing. execute returns that as a command error. run writes a line-numbered message and keeps scanning. A read or write failure means it cannot reliably continue reading commands or reporting their outcomes, so run returns the error. A successful state change may already have happened before writing its confirmation.
Completion is saved in this browser only. It does not measure mastery.