diff --git a/src/lib-sieve/sieve-error.c b/src/lib-sieve/sieve-error.c
index 5b6bdb8c62d6647e99936f8f1f65a4889d6214ab..926ad649e188b16548d708be5d6bd6bf85bf860d 100644
--- a/src/lib-sieve/sieve-error.c
+++ b/src/lib-sieve/sieve-error.c
@@ -41,8 +41,15 @@ const char *sieve_error_script_location
 
 	sname = ( script == NULL ? NULL : sieve_script_name(script) );
 
-	if ( sname == NULL || *sname == '\0' )
+	if ( sname == NULL || *sname == '\0' ) {
+		if ( source_line == 0 )
+			return NULL;
+
 		return t_strdup_printf("line %d", source_line);
+	}
+
+	if ( source_line == 0 )
+		return sname;
 
 	return t_strdup_printf("%s: line %d", sname, source_line);
 }