loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore(runner): return errors created by `connect` (#7222)

- Instead of creating errors via `google.golang.org/grpc`, use `connectrpc.com/connect`.
- This _avoids_ another dependency (still indirectly referenced in testing).

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7222
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>

authored by

Gusted
Gusted
and committed by
Earl Warren
ccd87001 511148db

+26 -39
-10
assets/go-licenses.json
··· 1060 1060 "licenseText": "Copyright 2009 The Go Authors.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n * Neither the name of Google LLC nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" 1061 1061 }, 1062 1062 { 1063 - "name": "google.golang.org/genproto/googleapis/rpc/status", 1064 - "path": "google.golang.org/genproto/googleapis/rpc/status/LICENSE", 1065 - "licenseText": "\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n" 1066 - }, 1067 - { 1068 - "name": "google.golang.org/grpc", 1069 - "path": "google.golang.org/grpc/LICENSE", 1070 - "licenseText": "\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n" 1071 - }, 1072 - { 1073 1063 "name": "google.golang.org/protobuf", 1074 1064 "path": "google.golang.org/protobuf/LICENSE", 1075 1065 "licenseText": "Copyright (c) 2018 The Go Authors. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n * Neither the name of Google Inc. nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
+1 -1
go.mod
··· 108 108 golang.org/x/sync v0.12.0 109 109 golang.org/x/sys v0.31.0 110 110 golang.org/x/text v0.23.0 111 - google.golang.org/grpc v1.71.0 112 111 google.golang.org/protobuf v1.36.4 113 112 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df 114 113 gopkg.in/ini.v1 v1.67.0 ··· 276 275 google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53 // indirect 277 276 google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect 278 277 google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect 278 + google.golang.org/grpc v1.71.0 // indirect 279 279 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect 280 280 gopkg.in/warnings.v0 v0.1.2 // indirect 281 281 )
+3 -5
routers/api/actions/runner/interceptor.go
··· 16 16 "code.gitea.io/gitea/modules/util" 17 17 18 18 "connectrpc.com/connect" 19 - "google.golang.org/grpc/codes" 20 - "google.golang.org/grpc/status" 21 19 ) 22 20 23 21 const ( ··· 37 35 runner, err := actions_model.GetRunnerByUUID(ctx, uuid) 38 36 if err != nil { 39 37 if errors.Is(err, util.ErrNotExist) { 40 - return nil, status.Error(codes.Unauthenticated, "unregistered runner") 38 + return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unregistered runner")) 41 39 } 42 - return nil, status.Error(codes.Internal, err.Error()) 40 + return nil, connect.NewError(connect.CodeInternal, err) 43 41 } 44 42 if subtle.ConstantTimeCompare([]byte(runner.TokenHash), []byte(auth_model.HashToken(token, runner.TokenSalt))) != 1 { 45 - return nil, status.Error(codes.Unauthenticated, "unregistered runner") 43 + return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("unregistered runner")) 46 44 } 47 45 48 46 cols := []string{"last_online"}
+22 -23
routers/api/actions/runner/runner.go
··· 6 6 import ( 7 7 "context" 8 8 "errors" 9 + "fmt" 9 10 "net/http" 10 11 11 12 actions_model "code.gitea.io/gitea/models/actions" ··· 20 21 "code.gitea.io/actions-proto-go/runner/v1/runnerv1connect" 21 22 "connectrpc.com/connect" 22 23 gouuid "github.com/google/uuid" 23 - "google.golang.org/grpc/codes" 24 - "google.golang.org/grpc/status" 25 24 ) 26 25 27 26 func NewRunnerServiceHandler() (string, http.Handler) { ··· 44 43 req *connect.Request[runnerv1.RegisterRequest], 45 44 ) (*connect.Response[runnerv1.RegisterResponse], error) { 46 45 if req.Msg.Token == "" || req.Msg.Name == "" { 47 - return nil, errors.New("missing runner token, name") 46 + return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("missing runner token, name")) 48 47 } 49 48 50 49 runnerToken, err := actions_model.GetRunnerToken(ctx, req.Msg.Token) 51 50 if err != nil { 52 - return nil, errors.New("runner registration token not found") 51 + return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("runner registration token not found")) 53 52 } 54 53 55 54 if !runnerToken.IsActive { 56 - return nil, errors.New("runner registration token has been invalidated, please use the latest one") 55 + return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("runner registration token has been invalidated, please use the latest one")) 57 56 } 58 57 59 58 if runnerToken.OwnerID > 0 { 60 59 if _, err := user_model.GetUserByID(ctx, runnerToken.OwnerID); err != nil { 61 - return nil, errors.New("owner of the token not found") 60 + return nil, connect.NewError(connect.CodeInternal, errors.New("owner of the token not found")) 62 61 } 63 62 } 64 63 65 64 if runnerToken.RepoID > 0 { 66 65 if _, err := repo_model.GetRepositoryByID(ctx, runnerToken.RepoID); err != nil { 67 - return nil, errors.New("repository of the token not found") 66 + return nil, connect.NewError(connect.CodeInternal, errors.New("repository of the token not found")) 68 67 } 69 68 } 70 69 ··· 81 80 AgentLabels: labels, 82 81 } 83 82 if err := runner.GenerateToken(); err != nil { 84 - return nil, errors.New("can't generate token") 83 + return nil, connect.NewError(connect.CodeInternal, errors.New("can't generate token")) 85 84 } 86 85 87 86 // create new runner 88 87 if err := actions_model.CreateRunner(ctx, runner); err != nil { 89 - return nil, errors.New("can't create new runner") 88 + return nil, connect.NewError(connect.CodeInternal, errors.New("can't create new runner")) 90 89 } 91 90 92 91 // update token status 93 92 runnerToken.IsActive = true 94 93 if err := actions_model.UpdateRunnerToken(ctx, runnerToken, "is_active"); err != nil { 95 - return nil, errors.New("can't update runner token status") 94 + return nil, connect.NewError(connect.CodeInternal, errors.New("can't update runner token status")) 96 95 } 97 96 98 97 res := connect.NewResponse(&runnerv1.RegisterResponse{ ··· 117 116 runner.AgentLabels = req.Msg.Labels 118 117 runner.Version = req.Msg.Version 119 118 if err := actions_model.UpdateRunner(ctx, runner, "agent_labels", "version"); err != nil { 120 - return nil, status.Errorf(codes.Internal, "update runner: %v", err) 119 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("update runner: %w", err)) 121 120 } 122 121 123 122 return connect.NewResponse(&runnerv1.DeclareResponse{ ··· 143 142 tasksVersion := req.Msg.TasksVersion // task version from runner 144 143 latestVersion, err := actions_model.GetTasksVersionByScope(ctx, runner.OwnerID, runner.RepoID) 145 144 if err != nil { 146 - return nil, status.Errorf(codes.Internal, "query tasks version failed: %v", err) 145 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("query tasks version failed: %w", err)) 147 146 } else if latestVersion == 0 { 148 147 if err := actions_model.IncreaseTaskVersion(ctx, runner.OwnerID, runner.RepoID); err != nil { 149 - return nil, status.Errorf(codes.Internal, "fail to increase task version: %v", err) 148 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("fail to increase task version: %w", err)) 150 149 } 151 150 // if we don't increase the value of `latestVersion` here, 152 151 // the response of FetchTask will return tasksVersion as zero. ··· 160 159 // try to pick a task for the runner that send the request. 161 160 if t, ok, err := actions_service.PickTask(ctx, runner); err != nil { 162 161 log.Error("pick task failed: %v", err) 163 - return nil, status.Errorf(codes.Internal, "pick task: %v", err) 162 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("pick task: %w", err)) 164 163 } else if ok { 165 164 task = t 166 165 } ··· 181 180 182 181 task, err := actions_model.UpdateTaskByState(ctx, runner.ID, req.Msg.State) 183 182 if err != nil { 184 - return nil, status.Errorf(codes.Internal, "update task: %v", err) 183 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("update task: %w", err)) 185 184 } 186 185 187 186 for k, v := range req.Msg.Outputs { ··· 210 209 } 211 210 212 211 if err := task.LoadJob(ctx); err != nil { 213 - return nil, status.Errorf(codes.Internal, "load job: %v", err) 212 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("load job: %w", err)) 214 213 } 215 214 if err := task.Job.LoadRun(ctx); err != nil { 216 - return nil, status.Errorf(codes.Internal, "load run: %v", err) 215 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("load run: %w", err)) 217 216 } 218 217 219 218 // don't create commit status for cron job ··· 247 246 248 247 task, err := actions_model.GetTaskByID(ctx, req.Msg.TaskId) 249 248 if err != nil { 250 - return nil, status.Errorf(codes.Internal, "get task: %v", err) 249 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("get task: %w", err)) 251 250 } else if runner.ID != task.RunnerID { 252 - return nil, status.Errorf(codes.Internal, "invalid runner for task") 251 + return nil, connect.NewError(connect.CodeInternal, errors.New("invalid runner for task")) 253 252 } 254 253 ack := task.LogLength 255 254 ··· 259 258 } 260 259 261 260 if task.LogInStorage { 262 - return nil, status.Errorf(codes.AlreadyExists, "log file has been archived") 261 + return nil, connect.NewError(connect.CodeAlreadyExists, errors.New("log file has been archived")) 263 262 } 264 263 265 264 rows := req.Msg.Rows[ack-req.Msg.Index:] 266 265 ns, err := actions.WriteLogs(ctx, task.LogFilename, task.LogSize, rows) 267 266 if err != nil { 268 - return nil, status.Errorf(codes.Internal, "write logs: %v", err) 267 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("write logs: %w", err)) 269 268 } 270 269 task.LogLength += int64(len(rows)) 271 270 for _, n := range ns { ··· 280 279 task.LogInStorage = true 281 280 remove, err = actions.TransferLogs(ctx, task.LogFilename) 282 281 if err != nil { 283 - return nil, status.Errorf(codes.Internal, "transfer logs: %v", err) 282 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("transfer logs: %w", err)) 284 283 } 285 284 } 286 285 287 286 if err := actions_model.UpdateTask(ctx, task, "log_indexes", "log_length", "log_size", "log_in_storage"); err != nil { 288 - return nil, status.Errorf(codes.Internal, "update task: %v", err) 287 + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("update task: %w", err)) 289 288 } 290 289 if remove != nil { 291 290 remove()