새 함수를 만드는 경우 Cloud Run의
콘솔 빠른 시작을 참고하세요.
Hello World 오류
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
오류 신고 방법을 보여줍니다.
더 살펴보기
이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.
코드 샘플
Go
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Java
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Node.js
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Python
Cloud Run Functions에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page demonstrates how to report errors in Cloud Run functions across multiple languages, including Go, Java, Node.js, and Python.\u003c/p\u003e\n"],["\u003cp\u003ePanics in Go code and uncaught exceptions in Java and Node.js will be reported to Error Reporting.\u003c/p\u003e\n"],["\u003cp\u003eIn Python, you can report exceptions to Error Reporting using the \u003ccode\u003egoogle.cloud.error_reporting\u003c/code\u003e library, and you may choose to either terminate the function or not.\u003c/p\u003e\n"],["\u003cp\u003ePrinting to \u003ccode\u003estdout\u003c/code\u003e or \u003ccode\u003estderr\u003c/code\u003e, using \u003ccode\u003elog.Fatal\u003c/code\u003e in Go, or logging severe errors in Java, and calling \u003ccode\u003eabort\u003c/code\u003e in python will not be reported to error reporting.\u003c/p\u003e\n"],["\u003cp\u003eSetting up Application Default Credentials is necessary for authenticating to Cloud Run functions.\u003c/p\u003e\n"]]],[],null,["# Hello World error\n\nDemonstrates how to report an error.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Report errors](https://firebase.google.com/docs/functions/reporting-errors)\n- [Report runtime function errors (1st gen)](/functions/1stgendocs/monitoring/error-reporting)\n\nCode sample\n-----------\n\n### Go\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n package tips\n\n import (\n \t\"fmt\"\n \t\"net/http\"\n \t\"os\"\n\n \t\"github.com/GoogleCloudPlatform/functions-framework-go/functions\"\n )\n\n func init() {\n \tfunctions.HTTP(\"HTTPError\", HTTPError)\n }\n\n // HTTPError describes how errors are handled in an HTTP function.\n func HTTPError(w http.ResponseWriter, r *http.Request) {\n \t// An error response code is NOT reported to Error Reporting.\n \t// http.Error(w, \"An error occurred\", http.StatusInternalServerError)\n\n \t// Printing to stdout and stderr is NOT reported to Error Reporting.\n \tfmt.Println(\"An error occurred (stdout)\")\n \tfmt.Fprintln(os.Stderr, \"An error occurred (stderr)\")\n\n \t// Calling log.Fatal sets a non-zero exit code and is NOT reported to Error\n \t// Reporting.\n \t// log.Fatal(\"An error occurred (log.Fatal)\")\n\n \t// Panics are reported to Error Reporting.\n \tpanic(\"An error occurred (panic)\")\n }\n\n### Java\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.cloud.functions.HttpFunction;\n import com.google.cloud.functions.HttpRequest;\n import com.google.cloud.functions.HttpResponse;\n import java.io.IOException;\n import java.util.logging.Logger;\n\n public class HelloError implements HttpFunction {\n\n private static final Logger logger = Logger.getLogger(HelloError.class.getName());\n\n @Override\n public void service(HttpRequest request, HttpResponse response)\n throws IOException {\n // These will NOT be reported to Error Reporting\n System.err.println(\"I failed you\");\n logger.severe(\"I failed you\");\n\n // This WILL be reported to Error Reporting\n throw new RuntimeException(\"I failed you\");\n }\n }\n\n### Node.js\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // These WILL be reported to Error Reporting\n throw new Error('I failed you'); // Will cause a cold start if not caught\n\n### Python\n\n\nTo authenticate to Cloud Run functions, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n @functions_framework.http\n def hello_error_1(request):\n # This WILL be reported to Error Reporting,\n # and WILL NOT show up in logs or\n # terminate the function.\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html()\n\n try:\n raise RuntimeError(\"I failed you\")\n except RuntimeError:\n https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.html.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html#google_cloud_error_reporting_client_Client_report_exception()\n\n # This WILL be reported to Error Reporting,\n # and WILL terminate the function\n raise RuntimeError(\"I failed you\")\n\n\n @functions_framework.http\n def hello_error_2(request):\n # These errors WILL NOT be reported to Error\n # Reporting, but will show up in logs.\n import logging\n import sys\n\n print(RuntimeError(\"I failed you (print to stdout)\"))\n logging.warning(RuntimeError(\"I failed you (logging.warning)\"))\n logging.error(RuntimeError(\"I failed you (logging.error)\"))\n sys.stderr.write(\"I failed you (sys.stderr.write)\\n\")\n\n # This is considered a successful execution and WILL NOT be reported\n # to Error Reporting, but the status code (500) WILL be logged.\n from flask import abort\n\n return abort(500)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=functions)."]]