From 542c732b94e0a5e7c02fd209a60bd068dbbfa03b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 4 Sep 2017 19:11:14 -0400 Subject: nslcd_proto: BREAKING CHANGE: Rethink the panic strategy nslcd_proto.Read() and .Write() panic() with any errors that they may need to emit. This made composition really simple, I was OK with it being against the normal Go style. But, I'm not happy with it anymore; have them return errors now. This leads us in to nslcd_server.HandleRequest() using those panics for control flow. Add a maybePanic(error) function to wrap all of the proto.Read() and proto.Write() calls to restore the panicing behavior. --- nslcd_server/func_handlerequest.go.gen | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'nslcd_server') diff --git a/nslcd_server/func_handlerequest.go.gen b/nslcd_server/func_handlerequest.go.gen index e7e2dcc..40e00c0 100755 --- a/nslcd_server/func_handlerequest.go.gen +++ b/nslcd_server/func_handlerequest.go.gen @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -*- Mode: Go -*- -# Copyright (C) 2015-2016 Luke Shumaker +# Copyright (C) 2015-2017 Luke Shumaker # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -35,12 +35,18 @@ import ( const sensitive = "" +func maybePanic(err error) { + if err != nil { + panic(err) + } +} + // Handle a request to nslcd func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred unix.Ucred) (err error) { defer func() { if r := recover(); r != nil { switch r := r.(type) { - case error: + case p.NslcdError: err = r default: panic(r) @@ -53,12 +59,12 @@ func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred unix.Ucred func handleRequest(backend Backend, in io.Reader, out io.Writer, cred unix.Ucred) { var version int32 - p.Read(in, &version) + maybePanic(p.Read(in, &version)) if version != p.NSLCD_VERSION { panic(p.NslcdError(fmt.Sprintf("Version mismatch: server=%#08x client=%#08x", p.NSLCD_VERSION, version))) } var action int32 - p.Read(in, &action) + maybePanic(p.Read(in, &action)) ch := make(chan interface{}) switch action { @@ -67,7 +73,7 @@ while read -r request; do cat <