mirror of
https://github.com/Cian-H/simple_blender_server.git
synced 2025-12-22 13:31:57 +00:00
Improved error handling
This commit is contained in:
28
main.go
28
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,16 +97,16 @@ func handleCreateModel(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
cmd := exec.Command("blender", "-b", "--python", tmpFile.Name())
|
cmd := exec.Command("blender", "-b", "--python", tmpFile.Name())
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
blenderOutput := string(output)
|
||||||
blenderError := string(output)
|
if err != nil || strings.Contains(blenderOutput, "Traceback") || strings.Contains(blenderOutput, "Error:") {
|
||||||
log.Printf("Command execution failed: %v, Output: %s", err, blenderError)
|
log.Printf("Command execution failed: %v, Output: %s", err, blenderOutput)
|
||||||
errorResponse := struct {
|
errorResponse := struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
BlenderLog string `json:"blender_log"`
|
BlenderLog string `json:"blender_log"`
|
||||||
ExitCode string `json:"exit_code"`
|
ExitCode string `json:"exit_code"`
|
||||||
}{
|
}{
|
||||||
Error: "Blender render failed",
|
Error: "Blender render failed",
|
||||||
BlenderLog: blenderError,
|
BlenderLog: blenderOutput,
|
||||||
ExitCode: err.Error(),
|
ExitCode: err.Error(),
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@@ -114,23 +115,28 @@ func handleCreateModel(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Blender command executed; output: %s", string(output))
|
fileInfo, err := os.Stat(tempFilePath)
|
||||||
|
if os.IsNotExist(err) || fileInfo.Size() == 0 {
|
||||||
|
log.Printf("Error: GLB file was not created or is empty at %s", tempFilePath)
|
||||||
|
|
||||||
if _, err := os.Stat(tempFilePath); os.IsNotExist(err) {
|
|
||||||
log.Printf("Error: GLB file was not created at %s", tempFilePath)
|
|
||||||
errorResponse := struct {
|
errorResponse := struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Details string `json:"details"`
|
Details string `json:"details"`
|
||||||
|
BlenderLog string `json:"blender_log"`
|
||||||
}{
|
}{
|
||||||
Error: "Failed to generate GLB file",
|
Error: "Failed to generate GLB file",
|
||||||
Details: "The Blender process completed but did not generate a model file. This typically indicates an error in the model code.",
|
Details: "The Blender process completed but did not generate a valid model file. This typically indicates an error in the model code.",
|
||||||
|
BlenderLog: string(output),
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
json.NewEncoder(w).Encode(errorResponse)
|
json.NewEncoder(w).Encode(errorResponse)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Blender command executed; output: %s", string(output))
|
||||||
|
|
||||||
glbData, err := os.ReadFile(tempFilePath)
|
glbData, err := os.ReadFile(tempFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading GLB file: %v", err)
|
log.Printf("Error reading GLB file: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user