Skip to content

Commit fbfffe6

Browse files
committed
refactor: remove unnecessary struct
1 parent 64dc847 commit fbfffe6

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ results/
55
*.so
66
*.bc
77
tags
8+
plmustache.control
9+
sql/plmustache--*.sql

nix/pgExtension.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ stdenv.mkDerivation {
1111
mkdir -p $out/bin
1212
install -D ${extensionName}.so -t $out/lib
1313
14-
install -D -t $out/share/postgresql/extension sql/*.sql
14+
install -D -t $out/share/postgresql/extension sql/${extensionName}--*.sql
1515
install -D -t $out/share/postgresql/extension ${extensionName}.control
1616
'';
1717
}

src/observation.c

+15-19
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33

44
#include "observation.h"
55

6-
typedef struct {
7-
char buf[20];
8-
} mustach_error_msg;
9-
10-
static mustach_error_msg get_mustach_error_msg(int mustach_code){
6+
static const char *mustach_strerror(int mustach_code){
117
switch(mustach_code){
12-
case MUSTACH_ERROR_SYSTEM : return (mustach_error_msg){"system error"};
13-
case MUSTACH_ERROR_UNEXPECTED_END : return (mustach_error_msg){"unexpected end"};
14-
case MUSTACH_ERROR_EMPTY_TAG : return (mustach_error_msg){"empty tag"};
15-
case MUSTACH_ERROR_TAG_TOO_LONG : return (mustach_error_msg){"tag is too long"};
16-
case MUSTACH_ERROR_BAD_SEPARATORS : return (mustach_error_msg){"bad separators"};
17-
case MUSTACH_ERROR_TOO_DEEP : return (mustach_error_msg){"too deep"};
18-
case MUSTACH_ERROR_CLOSING : return (mustach_error_msg){"closing"};
19-
case MUSTACH_ERROR_BAD_UNESCAPE_TAG : return (mustach_error_msg){"bad unescape tag"};
20-
case MUSTACH_ERROR_INVALID_ITF : return (mustach_error_msg){"invalid itf"};
21-
case MUSTACH_ERROR_ITEM_NOT_FOUND : return (mustach_error_msg){"item not found"};
22-
case MUSTACH_ERROR_PARTIAL_NOT_FOUND: return (mustach_error_msg){"partial not found"};
23-
case MUSTACH_ERROR_UNDEFINED_TAG : return (mustach_error_msg){"undefined tag"};
24-
default : return (mustach_error_msg){"unknown"};
8+
case MUSTACH_ERROR_SYSTEM : return "system error";
9+
case MUSTACH_ERROR_UNEXPECTED_END : return "unexpected end";
10+
case MUSTACH_ERROR_EMPTY_TAG : return "empty tag";
11+
case MUSTACH_ERROR_TAG_TOO_LONG : return "tag is too long";
12+
case MUSTACH_ERROR_BAD_SEPARATORS : return "bad separators";
13+
case MUSTACH_ERROR_TOO_DEEP : return "too deep";
14+
case MUSTACH_ERROR_CLOSING : return "closing";
15+
case MUSTACH_ERROR_BAD_UNESCAPE_TAG : return "bad unescape tag";
16+
case MUSTACH_ERROR_INVALID_ITF : return "invalid itf";
17+
case MUSTACH_ERROR_ITEM_NOT_FOUND : return "item not found";
18+
case MUSTACH_ERROR_PARTIAL_NOT_FOUND: return "partial not found";
19+
case MUSTACH_ERROR_UNDEFINED_TAG : return "undefined tag";
20+
default : return "unknown";
2521
}
2622
}
2723

@@ -56,7 +52,7 @@ void ereporter(plmustache_observation o){
5652
break;
5753
case ERROR_MUSTACH:
5854
ereport(ERROR,
59-
errmsg("plmustache template processing failed: %s", get_mustach_error_msg(o.error_mustach_code).buf)
55+
errmsg("plmustache template processing failed: %s", mustach_strerror(o.error_mustach_code))
6056
);
6157
break;
6258
}

0 commit comments

Comments
 (0)