MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / writeMessageCodesFile

Function writeMessageCodesFile

cmd/generate-message-codes/main.go:139–152  ·  view source on GitHub ↗

writeMessageCodesFile generates and writes the CODES.md file

(data []byte, destinationFile string)

Source from the content-addressed store, hash-verified

137
138// writeMessageCodesFile generates and writes the CODES.md file
139func writeMessageCodesFile(data []byte, destinationFile string) error {
140 fh, err := os.Create(destinationFile)
141 if err != nil {
142 return fmt.Errorf("failed to open destination file %s (%w)", destinationFile, err)
143 }
144 if _, err = fh.Write(data); err != nil {
145 _ = fh.Close()
146 return fmt.Errorf("failed to write to destination file %s (%w)", destinationFile, err)
147 }
148 if err := fh.Close(); err != nil {
149 return fmt.Errorf("failed to close destination file %s (%w)", destinationFile, err)
150 }
151 return nil
152}
153
154// mustWriteMessageCodesFile is identical to writeMessageCodesFile but panics on error.
155func mustWriteMessageCodesFile(data []byte, destinationFile string) {

Callers 1

Calls 3

ErrorfMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected