| 
									
										
										
										
											2022-09-15 00:19:57 +08:00
										 |  |  | package plugins | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-31 18:00:40 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/authlib/types" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/apimachinery/errutil" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/apimachinery/identity" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2022-09-15 00:19:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | var ( | 
					
						
							| 
									
										
										
										
											2023-09-25 17:56:03 +08:00
										 |  |  | 	errPluginNotRegisteredBase = errutil.NotFound("plugin.notRegistered", | 
					
						
							|  |  |  | 		errutil.WithPublicMessage("Plugin not registered")) | 
					
						
							| 
									
										
										
										
											2022-09-15 00:19:57 +08:00
										 |  |  | 	// ErrPluginNotRegistered error returned when a plugin is not registered.
 | 
					
						
							| 
									
										
										
										
											2023-09-25 17:56:03 +08:00
										 |  |  | 	ErrPluginNotRegistered = errPluginNotRegisteredBase.Errorf("plugin not registered") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	errPluginUnavailableBase = errutil.Internal("plugin.unavailable", | 
					
						
							|  |  |  | 		errutil.WithPublicMessage("Plugin unavailable")) | 
					
						
							| 
									
										
										
										
											2022-09-15 00:19:57 +08:00
										 |  |  | 	// ErrPluginUnavailable error returned when a plugin is unavailable.
 | 
					
						
							| 
									
										
										
										
											2023-09-25 17:56:03 +08:00
										 |  |  | 	ErrPluginUnavailable = errPluginUnavailableBase.Errorf("plugin unavailable") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	errMethodNotImplementedBase = errutil.NotFound("plugin.notImplemented", | 
					
						
							|  |  |  | 		errutil.WithPublicMessage("Method not implemented")) | 
					
						
							| 
									
										
										
										
											2022-09-15 00:19:57 +08:00
										 |  |  | 	// ErrMethodNotImplemented error returned when a plugin method is not implemented.
 | 
					
						
							| 
									
										
										
										
											2023-09-25 17:56:03 +08:00
										 |  |  | 	ErrMethodNotImplemented = errMethodNotImplementedBase.Errorf("method not implemented") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 15:44:43 +08:00
										 |  |  | 	// ErrPluginHealthCheck error returned when a plugin fails its health check.
 | 
					
						
							|  |  |  | 	// Exposed as a base error to wrap it with plugin error.
 | 
					
						
							|  |  |  | 	ErrPluginHealthCheck = errutil.Internal("plugin.healthCheck", | 
					
						
							|  |  |  | 		errutil.WithPublicMessage("Plugin health check failed"), | 
					
						
							|  |  |  | 		errutil.WithDownstream()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-20 17:23:53 +08:00
										 |  |  | 	// ErrPluginRequestFailureErrorBase error returned when a plugin request fails.
 | 
					
						
							|  |  |  | 	// Exposed as a base error to wrap it with plugin request errors.
 | 
					
						
							|  |  |  | 	ErrPluginRequestFailureErrorBase = errutil.Internal("plugin.requestFailureError", | 
					
						
							| 
									
										
										
										
											2023-09-11 18:13:13 +08:00
										 |  |  | 		errutil.WithPublicMessage("An error occurred within the plugin"), | 
					
						
							|  |  |  | 		errutil.WithDownstream()) | 
					
						
							| 
									
										
										
										
											2023-10-10 18:28:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ErrPluginRequestCanceledErrorBase error returned when a plugin request
 | 
					
						
							|  |  |  | 	// is cancelled by the client (context is cancelled).
 | 
					
						
							|  |  |  | 	// Exposed as a base error to wrap it with plugin cancelled errors.
 | 
					
						
							|  |  |  | 	ErrPluginRequestCanceledErrorBase = errutil.ClientClosedRequest("plugin.requestCanceled", | 
					
						
							|  |  |  | 		errutil.WithPublicMessage("Plugin request canceled")) | 
					
						
							| 
									
										
										
										
											2025-03-21 01:44:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ErrPluginGrpcResourceExhaustedBase error returned when a plugin response is larger than the grpc limit.
 | 
					
						
							|  |  |  | 	// Exposed as a base error to wrap it with plugin resource exhausted errors.
 | 
					
						
							|  |  |  | 	ErrPluginGrpcResourceExhaustedBase = errutil.Internal("plugin.resourceExhausted", | 
					
						
							|  |  |  | 		errutil.WithPublicMessage("The response is too large. Please try to reduce the time range or narrow down your query to return fewer data points."), | 
					
						
							|  |  |  | 		errutil.WithDownstream()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-31 18:00:40 +08:00
										 |  |  | 	ErrPluginGrpcConnectionUnavailableBaseFn = func(ctx context.Context) errutil.Base { | 
					
						
							|  |  |  | 		pubMsg := "Data source became unavailable during request. Please try again." | 
					
						
							|  |  |  | 		if requester, err := identity.GetRequester(ctx); err == nil && requester != nil { | 
					
						
							|  |  |  | 			if namespace, err := types.ParseNamespace(requester.GetNamespace()); err == nil && namespace.StackID != 0 { | 
					
						
							|  |  |  | 				pubMsg += " If the problem persists, please contact customer support." | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return errutil.Internal("plugin.connectionUnavailable", errutil.WithPublicMessage(pubMsg)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-09-15 00:19:57 +08:00
										 |  |  | ) |