@@ -17,6 +17,7 @@ package org.zowe.kotlinsdk.zowe.config
17
17
import com.google.gson.Gson
18
18
import com.starxg.keytar.Keytar
19
19
import org.yaml.snakeyaml.Yaml
20
+ import org.zowe.kotlinsdk.exceptions.EmptyZoweConfigFileException
20
21
import java.io.ByteArrayInputStream
21
22
import java.io.InputStream
22
23
import java.nio.charset.Charset
@@ -87,9 +88,10 @@ private fun formProfiles (profiles: Map<String, ZoweConfigProfile>?) {
87
88
* Parses JSON string to [ZoweConfig] object model.
88
89
* @param configString JSON string with zowe config.
89
90
* @return [ZoweConfig] object model.
91
+ * @throws [com.google.gson.JsonSyntaxException] and [org.zowe.kotlinsdk.exceptions.EmptyZoweConfigFileException]
90
92
*/
91
93
fun parseConfigJson (configString : String ): ZoweConfig {
92
- val zoweConfig = Gson ().fromJson(configString, ZoweConfig ::class .java)
94
+ val zoweConfig = Gson ().fromJson(configString, ZoweConfig ::class .java) ? : throw EmptyZoweConfigFileException ()
93
95
zoweConfig.zosmfProfile = zoweConfig.profile(zoweConfig.defaults[" zosmf" ])
94
96
formProfiles(zoweConfig.profiles)
95
97
return zoweConfig
@@ -99,6 +101,7 @@ fun parseConfigJson(configString: String): ZoweConfig {
99
101
* Reads input stream and parse it to ZoweConfig object model.
100
102
* @param inputStream - stream with json string of zowe config.
101
103
* @return ZoweConfig object model.
104
+ * @throws [com.google.gson.JsonSyntaxException] and [org.zowe.kotlinsdk.exceptions.EmptyZoweConfigFileException]
102
105
*/
103
106
fun parseConfigJson (inputStream : InputStream ): ZoweConfig = parseConfigJson(String (inputStream.readBytes()))
104
107
0 commit comments