Re: [resend 1/8] reg: Add system error printing function
Jonathan Vollebregt <jnvsor(a)gmail.com> writes:
+static void reg_print_error(LSTATUS error_code) +{ + switch (error_code) + { + case ERROR_SUCCESS: + return; + case ERROR_BAD_COMMAND: + reg_message(STRING_INVALID_CMDLINE); + return; + default: + { + static const WCHAR error_string[] = {'%','0','5','d',':',' ','%','s',0}; + WCHAR *message = NULL; + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, error_code, 0, (WCHAR *)&message, 0, NULL); + + reg_message(STRING_ERROR); + reg_printfW(error_string, error_code, message); + LocalFree(message); + return; + } + } +}
I don't think that's an improvement. There may be a need for generic Win32 error printing through FormatMessage for unknown codes, but I don't see why you'd want to route all errors through it. In particular, having to make up your own Win32 error codes only to convert them back to string ids is quite ugly. -- Alexandre Julliard julliard(a)winehq.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 2015-02-17 um 10:56 schrieb Alexandre Julliard:
I don't think that's an improvement. There may be a need for generic Win32 error printing through FormatMessage for unknown codes, but I don't see why you'd want to route all errors through it. In particular, having to make up your own Win32 error codes only to convert them back to string ids is quite ugly. This kind of setup was originally my idea, so I might as well answer this question myself:
The basic plan is to let the advapi32 do as much of the error checking as possible and use the return value from the Reg* functions to tell the user what went wrong. There are a handful of failure modes that only apply to reg.exe and not advapi32 - in particular the currently unimplemented remote access and trailing backslashes. The default path with FormatMessage is a fallback for unexpected errors. This could be an ERR if it is preferred, but an ERR won't be visible in the program output. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJU4xS9AAoJEN0/YqbEcdMwlM4P/08NLLXwY8r+7Fpe5bMzE2EB 11S69loo5zcvdHsgMCaIC7g68PEPOlRvLv1a2krt87w/WhniFdg4UncexfZ58TVb uZa3X1YiZZ1eWBtbx4hZQV1Lf+/fPSI3jxu4B4lej2WVoNk8J3+MOUFLHfOBEX8s 7R5lGgE5X6aIK2NVJagexartswYHbhocsSxHVoWf52X9hrV1edXlTwy05YDMe9ak YoiCgJt8uhBfcdAFFZgwENt8trHcjXLEM7yYnCZ00xM9vv3X7xDu4ObGBhfhGDaM GInXvvlb8q3bjE4HvIslRrssGAaSNCX1FjsWdN6TJ4sM/Pm0w5rTIFURHSBOKMnF bMk/dfHtWfoiJ7r9fFubMLuji1FoG3ct7Bv0fACfhHljs55N1afs/kcNWEuvw78f wffM6j1/m2IXx3uRZkPvSbydNPPo/89YFME7ZE5SkE74QJMBG9/ojI1u9zH2bt34 SLjVp8M2GUhC13aCPbQ5vYqc1VZqJ+MuByul6dgVd4KvbQmjixH5r/TNIk7ZxNTo RxS0Lqy1GH5GkTDlOfrK4jFQCvlk9yBjUAwoqsVHYw+DCVseKoqlI8UWceIF4iBH UE0lz+IzNXr1IZHtDYAy6vA/0V58J9Ie/Spe3d6P6l4A/C/JsGgG846uD8hEzMML ng8Bka//045RP8QhPdPe =mFzt -----END PGP SIGNATURE-----
Stefan Dösinger <stefandoesinger(a)gmail.com> writes:
Am 2015-02-17 um 10:56 schrieb Alexandre Julliard:
I don't think that's an improvement. There may be a need for generic Win32 error printing through FormatMessage for unknown codes, but I don't see why you'd want to route all errors through it. In particular, having to make up your own Win32 error codes only to convert them back to string ids is quite ugly. This kind of setup was originally my idea, so I might as well answer this question myself:
The basic plan is to let the advapi32 do as much of the error checking as possible and use the return value from the Reg* functions to tell the user what went wrong. There are a handful of failure modes that only apply to reg.exe and not advapi32 - in particular the currently unimplemented remote access and trailing backslashes.
I'm not sure that's a good idea either. It forces you to use generic error messages that are usually not very informative. It's better to do things in a way that allows printing more detailed errors in cases that are found to be confusing to users. -- Alexandre Julliard julliard(a)winehq.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 2015-02-17 um 13:43 schrieb Alexandre Julliard:
I'm not sure that's a good idea either. It forces you to use generic error messages that are usually not very informative. It's better to do things in a way that allows printing more detailed errors in cases that are found to be confusing to users. Fwiw, native mostly just writes "SYNTAX ERROR", just internationalized, so you can't really check it in a script. There are some rare exceptions. The only one I remember is if you pass a negative number as REG_DWORD data.
My consideration was that reg.exe would duplicate some of the underlying function's logic and reg.exe would have to handle Reg* return values anyway. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJU42tQAAoJEN0/YqbEcdMwf1sP+wSqeajJ2czBhksAz14s5A53 6QE1KgDf42sf/X63Z3/wSVcd4WqnNFHPo6d59jgxWYa9uugcrIo2f+8U75zrgsMR vHhpstaedxcln9zCar7fnhO98WbQypb+Onc/23gq7VdQn2vKwXuDoODAZa2zevoz rxyVNFLDKbTQnnCH0QhuvybtZ218c/Ad4HG0HxLqaWSy9bfTCUwb84dFkcR7JVDE R5OmDuXOMV7xL4VSrITh/ILR8P37uLqgqccYyw9uzYDUhEVaegrzuLqmQT9jSpOm R0FWp06lKVR2fDqYgiCiALhlPy2OD6Wh/B6i4rVMCOfVc+ONMfm6DsIqMBhMz2Yc 5sZkR27fKIKmT7H/J4sr2pMHsw0UJUb/8ZWwWCHxotmcMnsFOSeWNv0TC+ep2s+f iyeJCQz9f4YRWtqU4XDe10QVaEIDBIgC3BdTt11nReAO24HovLOL8hh5/gqrfgzq 0JwqS30X0xKe127DxrmpiNXRnFG0lSoWK4+GPqJ8jGpIAZaK55bw59BNDWx2pb0/ M1Si0OG3FajlQ/KcYUFVRnbvkcTCRasUw3j5P5hAzxx2/pT8uhD187tRyIYbzM9S IT6QgIzjYJDugJt/n02a9mfPQFzPJJjv2Q9gsIKn7DQK53kJL4oGT9Y2mclOcPt+ QaT4vnZ2rJWw11Q4SmI6 =OXFO -----END PGP SIGNATURE-----
participants (2)
-
Alexandre Julliard -
Stefan Dösinger