Initial commit

This commit is contained in:
AlexSSD7 2023-08-25 15:12:19 +01:00
commit b905244626
17 changed files with 1462 additions and 0 deletions

31
vm/errors.go Normal file
View file

@ -0,0 +1,31 @@
package vm
import (
"fmt"
"strings"
"github.com/AlexSSD7/vldisk/utils"
"github.com/pkg/errors"
)
var (
ErrSSHUnavailable = errors.New("ssh unavailable")
)
func wrapErrWithLog(err error, msg, log string) error {
return errors.Wrapf(err, "%v %v", msg, getLogErrMsg(log))
}
func getLogErrMsg(s string) string {
logToInclude := strings.ReplaceAll(s, "\n", "\\n")
logToInclude = strings.TrimSuffix(logToInclude, "\\n")
logToInclude = utils.ClearUnprintableChars(logToInclude)
origLogLen := len(logToInclude)
const maxLogLen = 256
if origLogLen > maxLogLen {
logToInclude = fmt.Sprintf("[%v chars trimmed]", origLogLen) + logToInclude[len(logToInclude)-maxLogLen:]
}
return fmt.Sprintf("(log: '%v')", logToInclude)
}