Micro In Action: Error Handling Across Service Boundaries

Che Dan
ITNEXT
Published in
3 min readApr 5, 2020

--

How to pass structural error information between services in Go Micro v2

Photo by Sepp Rutz on Unsplash

In a distributed system, it is a common case that an error is produced by one service then returned to another one. It will be great if we could pass all structural errors across services without losing detail information.

The github.com/micro/go-micro/v2/errors package from Micro v2 serves exactly this purpose. Let me quote the introduction from the official documentation:

Go Micro provides abstractions and types for most things that occur in a distributed system including errors. By providing a core set of errors and the ability to define detailed error types we can consistently understand what’s going on beyond the typical Go error string

It is used throughout Micro v2 and provides the consistent Marshall/Unmarshall capability among all the services built upon Micro.

Definition

The error type is defined by ProtoBuf:

syntax = "proto3";package errors;message Error {
string id = 1;
int32 code = 2;
string detail = 3;
string status = 4;
};

The Golang code is generated from this ProtoBuf file. Each field has a conventional meaning in…

--

--